From a9a61b4de2935754028e167e198a8e952c8180db Mon Sep 17 00:00:00 2001 From: Quentin Oschatz Date: Fri, 12 Oct 2018 21:49:43 +0200 Subject: [PATCH] Add Kilometers/Hour to Miles/Hour conversion and reverse --- snippets/kphToMph.md | 14 ++++++++++++++ snippets/mphToKph.md | 14 ++++++++++++++ tag_database | 2 ++ test/kphToMph/kphToMph.js | 2 ++ test/kphToMph/kphToMph.test.js | 12 ++++++++++++ test/mphToKph/mphToKph.js | 2 ++ test/mphToKph/mphToKph.test.js | 12 ++++++++++++ 7 files changed, 58 insertions(+) create mode 100644 snippets/kphToMph.md create mode 100644 snippets/mphToKph.md create mode 100644 test/kphToMph/kphToMph.js create mode 100644 test/kphToMph/kphToMph.test.js create mode 100644 test/mphToKph/mphToKph.js create mode 100644 test/mphToKph/mphToKph.test.js diff --git a/snippets/kphToMph.md b/snippets/kphToMph.md new file mode 100644 index 000000000..ae260c7f4 --- /dev/null +++ b/snippets/kphToMph.md @@ -0,0 +1,14 @@ +### kphToMph + +Convert kilometers/hour to miles/hour. + +Multiply the constant of proportionality with the argument. + +```js +const kphToMph = (kph) => 0.621371192 * kph; +``` + +```js +kphToMph(10); //16.09344000614692 +kphToMph(345.4); //138.24264965280207 +``` diff --git a/snippets/mphToKph.md b/snippets/mphToKph.md new file mode 100644 index 000000000..9854cd977 --- /dev/null +++ b/snippets/mphToKph.md @@ -0,0 +1,14 @@ +### mphToKph + +Convert miles/hour to kilometers/hour. + +Multiply the constant of proportionality with the argument. + +```js +const mphToKph = (mph) => 1.6093440006146922 * mph; +``` + +```js +mphToKph(10); //16.09344000614692 +mphToKph(85.9); //138.24264965280207 +``` diff --git a/tag_database b/tag_database index cd05988b1..d98a9dc7a 100644 --- a/tag_database +++ b/tag_database @@ -168,6 +168,7 @@ isWritableStream:node,type,intermediate join:array,intermediate JSONtoCSV:array,string,object,advanced JSONToFile:node,json,intermediate +kphToMph:utility,beginner last:array,beginner lcm:math,recursion,beginner longestItem:array,string,utility,intermediate @@ -190,6 +191,7 @@ minBy:math,array,function,beginner minDate:date,math,beginner minN:array,math,beginner mostPerformant:utility,function +mphToKph:utility,beginner negate:function,beginner nest:object,intermediate nodeListToArray:browser,array,beginner diff --git a/test/kphToMph/kphToMph.js b/test/kphToMph/kphToMph.js new file mode 100644 index 000000000..c6eb3df7b --- /dev/null +++ b/test/kphToMph/kphToMph.js @@ -0,0 +1,2 @@ +const kphToMph = (kph) => 0.621371192 * kph; +module.exports = kphToMph; diff --git a/test/kphToMph/kphToMph.test.js b/test/kphToMph/kphToMph.test.js new file mode 100644 index 000000000..846957c90 --- /dev/null +++ b/test/kphToMph/kphToMph.test.js @@ -0,0 +1,12 @@ +const expect = require('expect'); +const kphToMph = require('./kphToMph.js'); + +test('kphToMph is a Function', () => { + expect(kphToMph).toBeInstanceOf(Function); +}); +test('Returns mph from kph.', () => { + expect(kphToMph(10)).toBe(6.21371192); +}); +test('Returns mph from kph.', () => { + expect(kphToMph(345.4)).toBe(214.62160971679998); +}); diff --git a/test/mphToKph/mphToKph.js b/test/mphToKph/mphToKph.js new file mode 100644 index 000000000..2322f4284 --- /dev/null +++ b/test/mphToKph/mphToKph.js @@ -0,0 +1,2 @@ +const mphToKph = (mph) => 1.6093440006146922 * mph; +module.exports = mphToKph; diff --git a/test/mphToKph/mphToKph.test.js b/test/mphToKph/mphToKph.test.js new file mode 100644 index 000000000..1d9ff3938 --- /dev/null +++ b/test/mphToKph/mphToKph.test.js @@ -0,0 +1,12 @@ +const expect = require('expect'); +const mphToKph = require('./mphToKph.js'); + +test('mphToKph is a Function', () => { + expect(mphToKph).toBeInstanceOf(Function); +}); +test('Returns kph from mph.', () => { + expect(mphToKph(10)).toBe(16.09344000614692); +}); +test('Returns kph from mph.', () => { + expect(mphToKph(85.9)).toBe(138.24264965280207); +});