diff --git a/snippets/celsiusToFahrenheit.md b/snippets/celsiusToFahrenheit.md new file mode 100644 index 000000000..1ac652a66 --- /dev/null +++ b/snippets/celsiusToFahrenheit.md @@ -0,0 +1,12 @@ +### celsiusToFahrenheit + +Celsius to Fahrenheit temperature conversion. + +Follows the conversion formula `F = 1.8C + 32` +```js +const celsiusToFahrenheit = degrees => 1.8 * degrees + 32; +``` + +```js +celsiusToFahrenheit(33) // '91.4' +``` diff --git a/snippets/fahrenheitToCelsius.md b/snippets/fahrenheitToCelsius.md new file mode 100644 index 000000000..1c9f11e6b --- /dev/null +++ b/snippets/fahrenheitToCelsius.md @@ -0,0 +1,12 @@ +### fahrenheitToCelsius + +Fahrenheit to Celsius temperature conversion. + +Follows the conversion formula `C = (F - 32) * 5/9` +```js +const fahrenheitToCelsius = degrees => (degrees - 32) * 5/9; +``` + +```js +fahrenheitToCelsius(32); // '0' +``` diff --git a/tag_database b/tag_database index 41f8e4564..812178e67 100644 --- a/tag_database +++ b/tag_database @@ -22,6 +22,7 @@ call:adapter,function,intermediate capitalize:string,array,intermediate capitalizeEveryWord:string,regexp,intermediate castArray:utility,array,type,beginner +celsiusToFahrenheit:utility,beginner chainAsync:function,intermediate chunk:array,intermediate clampNumber:math,beginner @@ -74,6 +75,7 @@ escapeRegExp:string,regexp,intermediate everyNth:array,beginner extendHex:utility,string,intermediate factorial:math,recursion,beginner +fahrenheitToCelsius:utility,beginner fibonacci:math,array,beginner filterNonUnique:array,beginner filterNonUniqueBy:array,function,intermediate diff --git a/test/celsiusToFahrenheit/celsiusToFahrenheit.js b/test/celsiusToFahrenheit/celsiusToFahrenheit.js new file mode 100644 index 000000000..1dd2e7b7d --- /dev/null +++ b/test/celsiusToFahrenheit/celsiusToFahrenheit.js @@ -0,0 +1,2 @@ +const celsiusToFahrenheit = degrees => 1.8 * degrees + 32; +module.exports = celsiusToFahrenheit; diff --git a/test/celsiusToFahrenheit/celsiusToFahrenheit.test.js b/test/celsiusToFahrenheit/celsiusToFahrenheit.test.js new file mode 100644 index 000000000..42f02c969 --- /dev/null +++ b/test/celsiusToFahrenheit/celsiusToFahrenheit.test.js @@ -0,0 +1,26 @@ +const expect = require('expect'); +const celsiusToFahrenheit = require('./celsiusToFahrenheit.js'); + +test('celsiusToFahrenheit is a Function', () => { + expect(celsiusToFahrenheit).toBeInstanceOf(Function); +}); + +test('0 Celsius is 32 Fahrenheit', () => { + expect(celsiusToFahrenheit(0)).toBe(32) +}) + +test('100 Celsius is 212 Fahrenheit', () => { + expect(celsiusToFahrenheit(100)).toBe(212) +}) + +test('-50 Celsius is -58 Fahrenheit', () => { + expect(celsiusToFahrenheit(-50)).toBe(-58) +}) + +test('1000 Celsius is 1832 Fahrenheit', () => { + expect(celsiusToFahrenheit(1000)).toBe(1832) +}) + +test('Not a number value is NaN', () => { + expect(celsiusToFahrenheit("Durr")).toBe(NaN) +}) \ No newline at end of file diff --git a/test/fahrenheitToCelsius/fahrenheitToCelsius.js b/test/fahrenheitToCelsius/fahrenheitToCelsius.js new file mode 100644 index 000000000..399fd0d61 --- /dev/null +++ b/test/fahrenheitToCelsius/fahrenheitToCelsius.js @@ -0,0 +1,2 @@ +const fahrenheitToCelsius = degrees => (degrees - 32) * 5/9; +module.exports = fahrenheitToCelsius; diff --git a/test/fahrenheitToCelsius/fahrenheitToCelsius.test.js b/test/fahrenheitToCelsius/fahrenheitToCelsius.test.js new file mode 100644 index 000000000..0ec80c38c --- /dev/null +++ b/test/fahrenheitToCelsius/fahrenheitToCelsius.test.js @@ -0,0 +1,26 @@ +const expect = require('expect'); +const fahrenheitToCelsius = require('./fahrenheitToCelsius.js'); + +test('fahrenheitToCelsius is a Function', () => { + expect(fahrenheitToCelsius).toBeInstanceOf(Function); +}); + +test('32 Fahrenheit is 0 Celsius', () => { + expect(fahrenheitToCelsius(32)).toBe(0) +}) + +test('212 Fahrenheit is 100 Celsius', () => { + expect(fahrenheitToCelsius(212)).toBe(100) +}) + +test('150 Fahrenheit is 65.55555555555556 Celsius', () => { + expect(fahrenheitToCelsius(150)).toBe(65.55555555555556) +}) + +test('1000 Fahrenheit is 537.7777777777778', () => { + expect(fahrenheitToCelsius(1000)).toBe(537.7777777777778) +}) + +test('Not a number value is NaN', () => { + expect(fahrenheitToCelsius("Durr")).toBe(NaN) +}) \ No newline at end of file