diff --git a/snippets/isSameDate.md b/snippets/isSameDate.md index 07041b84f..5e30edf4d 100644 --- a/snippets/isSameDate.md +++ b/snippets/isSameDate.md @@ -2,10 +2,10 @@ Check if a date is the same as another date. -Use strict equality checking (`===`) to check if the first date is the same as the second one. +Use `Date.prototype.toISOString()` and strict equality checking (`===`) to check if the first date is the same as the second one. ```js -const isSameDate = (dateA, dateB) => dateA === dateB; +const isSameDate = (dateA, dateB) => dateA.toISOString() === dateB.toISOString(); ``` ```js diff --git a/test/dayOfYear/dayOfYear.js b/test/dayOfYear/dayOfYear.js new file mode 100644 index 000000000..8c6042edf --- /dev/null +++ b/test/dayOfYear/dayOfYear.js @@ -0,0 +1,3 @@ +const dayOfYear = date => + Math.floor((date - new Date(date.getFullYear(), 0, 0)) / 1000 / 60 / 60 / 24); +module.exports = dayOfYear; diff --git a/test/dayOfYear/dayOfYear.test.js b/test/dayOfYear/dayOfYear.test.js new file mode 100644 index 000000000..2df870a58 --- /dev/null +++ b/test/dayOfYear/dayOfYear.test.js @@ -0,0 +1,6 @@ +const expect = require('expect'); +const dayOfYear = require('./dayOfYear.js'); + +test('dayOfYear is a Function', () => { + expect(dayOfYear).toBeInstanceOf(Function); +}); diff --git a/test/degreesToRads/degreesToRads.js b/test/degreesToRads/degreesToRads.js index ffc04f7fd..786f112e3 100644 --- a/test/degreesToRads/degreesToRads.js +++ b/test/degreesToRads/degreesToRads.js @@ -1,2 +1,2 @@ -const degreesToRads = deg => (deg * Math.PI) / 180.0; +const degreesToRads = deg => deg * Math.PI / 180.0; module.exports = degreesToRads; diff --git a/test/getMeridiemSuffixOfInteger/getMeridiemSuffixOfInteger.js b/test/getMeridiemSuffixOfInteger/getMeridiemSuffixOfInteger.js index 6e91ea80c..8728f3637 100644 --- a/test/getMeridiemSuffixOfInteger/getMeridiemSuffixOfInteger.js +++ b/test/getMeridiemSuffixOfInteger/getMeridiemSuffixOfInteger.js @@ -4,6 +4,6 @@ const getMeridiemSuffixOfInteger = num => : num === 12 ? 12 + 'pm' : num < 12 - ? (num % 12) + 'am' - : (num % 12) + 'pm'; + ? num % 12 + 'am' + : num % 12 + 'pm'; module.exports = getMeridiemSuffixOfInteger; diff --git a/test/hz/hz.js b/test/hz/hz.js index 7172074bb..c7d0b997b 100644 --- a/test/hz/hz.js +++ b/test/hz/hz.js @@ -1,6 +1,6 @@ const hz = (fn, iterations = 100) => { const before = performance.now(); for (let i = 0; i < iterations; i++) fn(); - return (1000 * iterations) / (performance.now() - before); + return 1000 * iterations / (performance.now() - before); }; module.exports = hz; diff --git a/test/isAfterDate/isAfterDate.js b/test/isAfterDate/isAfterDate.js new file mode 100644 index 000000000..e489c8439 --- /dev/null +++ b/test/isAfterDate/isAfterDate.js @@ -0,0 +1,2 @@ +const isAfterDate = (dateA, dateB) => dateA > dateB; +module.exports = isAfterDate; diff --git a/test/isAfterDate/isAfterDate.test.js b/test/isAfterDate/isAfterDate.test.js new file mode 100644 index 000000000..4332eab5a --- /dev/null +++ b/test/isAfterDate/isAfterDate.test.js @@ -0,0 +1,12 @@ +const expect = require('expect'); +const isAfterDate = require('./isAfterDate.js'); + +test('isAfterDate is a Function', () => { + expect(isAfterDate).toBeInstanceOf(Function); +}); +test('isAfterDate produces the correct result', () => { + expect(isAfterDate(new Date(2010, 10, 21), new Date(2010, 10, 20))).toBeTruthy(); +}); +test('isBeforeDate produces the correct result', () => { + expect(isAfterDate(new Date(2010, 10, 20), new Date(2010, 10, 21))).toBeFalsy(); +}); diff --git a/test/isBeforeDate/isBeforeDate.js b/test/isBeforeDate/isBeforeDate.js new file mode 100644 index 000000000..cd6207544 --- /dev/null +++ b/test/isBeforeDate/isBeforeDate.js @@ -0,0 +1,2 @@ +const isBeforeDate = (dateA, dateB) => dateA < dateB; +module.exports = isBeforeDate; diff --git a/test/isBeforeDate/isBeforeDate.test.js b/test/isBeforeDate/isBeforeDate.test.js new file mode 100644 index 000000000..5656970c1 --- /dev/null +++ b/test/isBeforeDate/isBeforeDate.test.js @@ -0,0 +1,13 @@ +const expect = require('expect'); +const isBeforeDate = require('./isBeforeDate.js'); + +test('isBeforeDate is a Function', () => { + expect(isBeforeDate).toBeInstanceOf(Function); +}); +test('isBeforeDate produces the correct result', () => { + expect(isBeforeDate(new Date(2010, 10, 20), new Date(2010, 10, 21))).toBeTruthy(); +}); +test('isBeforeDate produces the correct result', () => { + expect(isBeforeDate(new Date(2010, 10, 21), new Date(2010, 10, 20))).toBeFalsy(); +}); + diff --git a/test/isSameDate/isSameDate.js b/test/isSameDate/isSameDate.js new file mode 100644 index 000000000..3bd6f2218 --- /dev/null +++ b/test/isSameDate/isSameDate.js @@ -0,0 +1,2 @@ +const isSameDate = (dateA, dateB) => dateA.toISOString() === dateB.toISOString(); +module.exports = isSameDate; diff --git a/test/isSameDate/isSameDate.test.js b/test/isSameDate/isSameDate.test.js new file mode 100644 index 000000000..2b6e8cbd4 --- /dev/null +++ b/test/isSameDate/isSameDate.test.js @@ -0,0 +1,12 @@ +const expect = require('expect'); +const isSameDate = require('./isSameDate.js'); + +test('isSameDate is a Function', () => { + expect(isSameDate).toBeInstanceOf(Function); +}); +test('isSameDate produces the correct result', () => { + expect(isSameDate(new Date(2010, 10, 20), new Date(2010, 10, 20))).toBeTruthy(); +}); +test('isSameDate produces the correct result', () => { + expect(isSameDate(new Date(2010, 10, 20), new Date(2010, 10, 21))).toBeFalsy(); +}); diff --git a/test/lcm/lcm.js b/test/lcm/lcm.js index a4d8b1032..60ef96de8 100644 --- a/test/lcm/lcm.js +++ b/test/lcm/lcm.js @@ -1,6 +1,6 @@ const lcm = (...arr) => { const gcd = (x, y) => (!y ? x : gcd(y, x % y)); - const _lcm = (x, y) => (x * y) / gcd(x, y); + const _lcm = (x, y) => x * y / gcd(x, y); return [...arr].reduce((a, b) => _lcm(a, b)); }; module.exports = lcm; diff --git a/test/luhnCheck/luhnCheck.js b/test/luhnCheck/luhnCheck.js index d666a021a..20a62dd17 100644 --- a/test/luhnCheck/luhnCheck.js +++ b/test/luhnCheck/luhnCheck.js @@ -4,7 +4,7 @@ const luhnCheck = num => { .reverse() .map(x => parseInt(x)); let lastDigit = arr.splice(0, 1)[0]; - let sum = arr.reduce((acc, val, i) => (i % 2 !== 0 ? acc + val : acc + ((val * 2) % 9) || 9), 0); + let sum = arr.reduce((acc, val, i) => (i % 2 !== 0 ? acc + val : acc + (val * 2) % 9 || 9), 0); sum += lastDigit; return sum % 10 === 0; }; diff --git a/test/maxDate/maxDate.js b/test/maxDate/maxDate.js new file mode 100644 index 000000000..b2413c849 --- /dev/null +++ b/test/maxDate/maxDate.js @@ -0,0 +1,2 @@ +const maxDate = (...dates) => new Date(Math.max.apply(null, ...dates)); +module.exports = maxDate; diff --git a/test/maxDate/maxDate.test.js b/test/maxDate/maxDate.test.js new file mode 100644 index 000000000..e7d6ae60c --- /dev/null +++ b/test/maxDate/maxDate.test.js @@ -0,0 +1,15 @@ +const expect = require('expect'); +const maxDate = require('./maxDate.js'); + +test('maxDate is a Function', () => { + expect(maxDate).toBeInstanceOf(Function); +}); +test('maxDate produces the maximum date', () => { + const array = [ + new Date(2017, 4, 13), + new Date(2018, 2, 12), + new Date(2016, 0, 10), + new Date(2016, 0, 9) + ]; + expect(maxDate(array)).toEqual(new Date(2018, 2, 12)); +}); diff --git a/test/minDate/minDate.js b/test/minDate/minDate.js new file mode 100644 index 000000000..a740098ed --- /dev/null +++ b/test/minDate/minDate.js @@ -0,0 +1,2 @@ +const minDate = (...dates) => new Date(Math.min.apply(null, ...dates)); +module.exports = minDate; diff --git a/test/minDate/minDate.test.js b/test/minDate/minDate.test.js new file mode 100644 index 000000000..7156eb98b --- /dev/null +++ b/test/minDate/minDate.test.js @@ -0,0 +1,15 @@ +const expect = require('expect'); +const minDate = require('./minDate.js'); + +test('minDate is a Function', () => { + expect(minDate).toBeInstanceOf(Function); +}); +test('minDate produces the maximum date', () => { + const array = [ + new Date(2017, 4, 13), + new Date(2018, 2, 12), + new Date(2016, 0, 10), + new Date(2016, 0, 9) + ]; + expect(minDate(array)).toEqual(new Date(2016, 0, 9)); +}); diff --git a/test/percentile/percentile.js b/test/percentile/percentile.js index 07669d78b..fd32602d2 100644 --- a/test/percentile/percentile.js +++ b/test/percentile/percentile.js @@ -1,3 +1,3 @@ const percentile = (arr, val) => - (100 * arr.reduce((acc, v) => acc + (v < val ? 1 : 0) + (v === val ? 0.5 : 0), 0)) / arr.length; + 100 * arr.reduce((acc, v) => acc + (v < val ? 1 : 0) + (v === val ? 0.5 : 0), 0) / arr.length; module.exports = percentile; diff --git a/test/radsToDegrees/radsToDegrees.js b/test/radsToDegrees/radsToDegrees.js index fde727a2f..214e5defa 100644 --- a/test/radsToDegrees/radsToDegrees.js +++ b/test/radsToDegrees/radsToDegrees.js @@ -1,2 +1,2 @@ -const radsToDegrees = rad => (rad * 180.0) / Math.PI; +const radsToDegrees = rad => rad * 180.0 / Math.PI; module.exports = radsToDegrees;