diff --git a/snippet-template.md b/snippet-template.md index 1ee62a2f0..31cc8b26d 100644 --- a/snippet-template.md +++ b/snippet-template.md @@ -10,5 +10,5 @@ const functionName = arguments => ``` ```js -functionName('sampleInput') // 'sampleOutput' +functionName('sampleInput'); // 'sampleOutput' ``` diff --git a/snippets/degreesToRads.md b/snippets/degreesToRads.md new file mode 100644 index 000000000..ed3a2ee0e --- /dev/null +++ b/snippets/degreesToRads.md @@ -0,0 +1,13 @@ +### degreesToRads + +Converts an angle from degrees to radians. + +Use `Math.PI` and the degree to radian formula to convert the angle from degrees to radians. + +```js +const degreesToRads = deg => deg * Math.PI / 180.0; +``` + +```js +degreesToRads(90.0); // ~1.5708 +``` diff --git a/snippets/radsToDegrees.md b/snippets/radsToDegrees.md new file mode 100644 index 000000000..d8dd54958 --- /dev/null +++ b/snippets/radsToDegrees.md @@ -0,0 +1,13 @@ +### radsToDegrees + +Converts an angle from radians to degrees. + +Use `Math.PI` and the radian to degree formula to convert the angle from radians to degrees. + +```js +const radsToDegrees = rad => rad * 180.0 / Math.PI; +``` + +```js +radsToDegrees(Math.PI / 2); // 90 +``` diff --git a/tag_database b/tag_database index c69f793c6..b608bd0c8 100644 --- a/tag_database +++ b/tag_database @@ -42,6 +42,7 @@ deepClone:object,recursion deepFlatten:array,recursion defaults:object defer:function +degreesToRads:math delay:function detectDeviceType:browser difference:array,math @@ -189,6 +190,7 @@ pull:array pullAtIndex:array pullAtValue:array pullBy:array,function,advanced +radsToDegrees:math randomHexColorCode:utility,random randomIntArrayInRange:math,utility,random randomIntegerInRange:math,utility,random diff --git a/test/bifurcate/bifurcate.js b/test/bifurcate/bifurcate.js index 86fc9f7c1..95d7f8f50 100644 --- a/test/bifurcate/bifurcate.js +++ b/test/bifurcate/bifurcate.js @@ -1,6 +1,3 @@ const bifurcate = (arr, filter) => -arr.reduce((acc, val, i) => (acc[filter[i] ? 0 : 1].push(val), acc), [ -[], -[], -]); +arr.reduce((acc, val, i) => (acc[filter[i] ? 0 : 1].push(val), acc), [[], []]); module.exports = bifurcate; \ No newline at end of file diff --git a/test/bifurcateBy/bifurcateBy.js b/test/bifurcateBy/bifurcateBy.js index fb153edd7..bdf04a7ce 100644 --- a/test/bifurcateBy/bifurcateBy.js +++ b/test/bifurcateBy/bifurcateBy.js @@ -1,6 +1,3 @@ const bifurcateBy = (arr, fn) => -arr.reduce((acc, val, i) => (acc[fn(val, i) ? 0 : 1].push(val), acc), [ -[], -[], -]); +arr.reduce((acc, val, i) => (acc[fn(val, i) ? 0 : 1].push(val), acc), [[], []]); module.exports = bifurcateBy; \ No newline at end of file diff --git a/test/degreesToRads/degreesToRads.js b/test/degreesToRads/degreesToRads.js new file mode 100644 index 000000000..da6d51836 --- /dev/null +++ b/test/degreesToRads/degreesToRads.js @@ -0,0 +1,2 @@ +const degreesToRads = deg => deg * Math.PI / 180.0; +module.exports = degreesToRads; \ No newline at end of file diff --git a/test/degreesToRads/degreesToRads.test.js b/test/degreesToRads/degreesToRads.test.js new file mode 100644 index 000000000..8ec980a10 --- /dev/null +++ b/test/degreesToRads/degreesToRads.test.js @@ -0,0 +1,15 @@ +const test = require('tape'); +const degreesToRads = require('./degreesToRads.js'); + +test('Testing degreesToRads', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + const approxeq = (v1,v2, diff = 0.001) => Math.abs(v1 - v2) < diff; // Use to account for rounding errors + t.true(typeof degreesToRads === 'function', 'degreesToRads is a Function'); + t.true(approxeq(degreesToRads(90.0), Math.PI / 2), 'Returns the appropriate value'); + //t.deepEqual(degreesToRads(args..), 'Expected'); + //t.equal(degreesToRads(args..), 'Expected'); + //t.false(degreesToRads(args..), 'Expected'); + //t.throws(degreesToRads(args..), 'Expected'); + t.end(); +}); diff --git a/test/radsToDegrees/radsToDegrees.js b/test/radsToDegrees/radsToDegrees.js new file mode 100644 index 000000000..d9a370b78 --- /dev/null +++ b/test/radsToDegrees/radsToDegrees.js @@ -0,0 +1,2 @@ +const radsToDegrees = rad => rad * 180.0 / Math.PI; +module.exports = radsToDegrees; \ No newline at end of file diff --git a/test/radsToDegrees/radsToDegrees.test.js b/test/radsToDegrees/radsToDegrees.test.js new file mode 100644 index 000000000..446485d76 --- /dev/null +++ b/test/radsToDegrees/radsToDegrees.test.js @@ -0,0 +1,14 @@ +const test = require('tape'); +const radsToDegrees = require('./radsToDegrees.js'); + +test('Testing radsToDegrees', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof radsToDegrees === 'function', 'radsToDegrees is a Function'); + t.equal(radsToDegrees(Math.PI / 2), 90, 'Returns the appropriate value'); + //t.deepEqual(radsToDegrees(args..), 'Expected'); + //t.equal(radsToDegrees(args..), 'Expected'); + //t.false(radsToDegrees(args..), 'Expected'); + //t.throws(radsToDegrees(args..), 'Expected'); + t.end(); +}); diff --git a/test/testlog b/test/testlog index f7972c818..f4af90680 100644 --- a/test/testlog +++ b/test/testlog @@ -1,4 +1,4 @@ -Test log for: Wed Feb 14 2018 12:12:48 GMT+0200 (GTB Standard Time) +Test log for: Wed Feb 14 2018 12:24:07 GMT+0200 (GTB Standard Time) > 30-seconds-of-code@0.0.1 test G:\My Files\git Repositories\30-seconds-of-code > tape test/**/*.test.js | tap-spec @@ -278,6 +278,11 @@ Test log for: Wed Feb 14 2018 12:12:48 GMT+0200 (GTB Standard Time) √ defer is a Function + Testing degreesToRads + + √ degreesToRads is a Function + √ Returns the appropriate value + Testing delay √ delay is a Function @@ -1221,6 +1226,11 @@ Test log for: Wed Feb 14 2018 12:12:48 GMT+0200 (GTB Standard Time) √ quickSort(undefined) throws an error √ quickSort([11, 1, 324, 23232, -1, 53, 2, 524, 32, 13, 156, 133, 62, 12, 4]) takes less than 2s to run + Testing radsToDegrees + + √ radsToDegrees is a Function + √ Returns the appropriate value + Testing randomHexColorCode √ randomHexColorCode is a Function @@ -1820,8 +1830,8 @@ Test log for: Wed Feb 14 2018 12:12:48 GMT+0200 (GTB Standard Time) √ Works with multiple promises - total: 909 - passing: 909 + total: 913 + passing: 913 duration: 2.4s