diff --git a/snippets/compose.md b/snippets/compose.md index 778e10eef..b1788140a 100644 --- a/snippets/compose.md +++ b/snippets/compose.md @@ -12,9 +12,6 @@ const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args))); ```js const add5 = x => x + 5; const multiply = (x, y) => x * y; -const multiplyAndAdd5 = compose( - add5, - multiply -); +const multiplyAndAdd5 = compose(add5, multiply); multiplyAndAdd5(5, 2); // 15 ``` diff --git a/snippets/dayOfYear.md b/snippets/dayOfYear.md index e40640777..7653f3481 100644 --- a/snippets/dayOfYear.md +++ b/snippets/dayOfYear.md @@ -6,9 +6,8 @@ Use `new Date()` and `Date.prototype.getFullYear()` to get the first day of the Use `Math.floor()` to appropriately round the resulting day count to an integer. ```js -const dayOfYear = date => Math.floor( - (date - new Date(date.getFullYear(), 0, 0)) / 1000 / 60 / 60 / 24 -); +const dayOfYear = date => + Math.floor((date - new Date(date.getFullYear(), 0, 0)) / 1000 / 60 / 60 / 24); ``` ```js diff --git a/snippets/degreesToRads.md b/snippets/degreesToRads.md index 90790765d..ed3a2ee0e 100644 --- a/snippets/degreesToRads.md +++ b/snippets/degreesToRads.md @@ -5,7 +5,7 @@ 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; +const degreesToRads = deg => deg * Math.PI / 180.0; ``` ```js diff --git a/snippets/getMeridiemSuffixOfInteger.md b/snippets/getMeridiemSuffixOfInteger.md index 9cf6e46c3..ea153f7b2 100644 --- a/snippets/getMeridiemSuffixOfInteger.md +++ b/snippets/getMeridiemSuffixOfInteger.md @@ -11,8 +11,8 @@ const getMeridiemSuffixOfInteger = num => : num === 12 ? 12 + 'pm' : num < 12 - ? (num % 12) + 'am' - : (num % 12) + 'pm'; + ? num % 12 + 'am' + : num % 12 + 'pm'; ``` ```js diff --git a/snippets/hz.md b/snippets/hz.md index c1e9c0ceb..08cff5de6 100644 --- a/snippets/hz.md +++ b/snippets/hz.md @@ -11,7 +11,7 @@ Omit the second argument, `iterations`, to use the default of 100 iterations. 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); }; ``` diff --git a/snippets/isAfterDate.md b/snippets/isAfterDate.md new file mode 100644 index 000000000..02bdc9789 --- /dev/null +++ b/snippets/isAfterDate.md @@ -0,0 +1,13 @@ +### isAfterDate + +Check if a date is after another date. + +Use the greater than operator (`>`) to check if the first date comes after the second one. + +```js +const isAfterDate = (dateA, dateB) => dateA > dateB; +``` + +```js +isAfterDate(new Date(2010, 10, 21), new Date(2010, 10, 20)); // true +``` diff --git a/snippets/isBeforeDate.md b/snippets/isBeforeDate.md new file mode 100644 index 000000000..3c0d2c2af --- /dev/null +++ b/snippets/isBeforeDate.md @@ -0,0 +1,13 @@ +### isBeforeDate + +Check if a date is before another date. + +Use the less than operator (`<`) to check if the first date comes before the second one. + +```js +const isBeforeDate = (dateA, dateB) => dateA < dateB; +``` + +```js +isBeforeDate(new Date(2010, 10, 20), new Date(2010, 10, 21)); // true +``` diff --git a/snippets/isSameDate.md b/snippets/isSameDate.md new file mode 100644 index 000000000..07041b84f --- /dev/null +++ b/snippets/isSameDate.md @@ -0,0 +1,13 @@ +### isSameDate + +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. + +```js +const isSameDate = (dateA, dateB) => dateA === dateB; +``` + +```js +isSameDate(new Date(2010, 10, 20), new Date(2010, 10, 20)); // true +``` diff --git a/snippets/lcm.md b/snippets/lcm.md index 970e3083c..74f346af3 100644 --- a/snippets/lcm.md +++ b/snippets/lcm.md @@ -8,7 +8,7 @@ The GCD formula uses recursion. ```js 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)); }; ``` diff --git a/snippets/luhnCheck.md b/snippets/luhnCheck.md index c99532ed1..9c8bf0152 100644 --- a/snippets/luhnCheck.md +++ b/snippets/luhnCheck.md @@ -15,7 +15,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/snippets/maxDate.md b/snippets/maxDate.md index bf2677476..ffa784528 100644 --- a/snippets/maxDate.md +++ b/snippets/maxDate.md @@ -13,7 +13,7 @@ const array = [ new Date(2017, 4, 13), new Date(2018, 2, 12), new Date(2016, 0, 10), - new Date(2016, 0, 9), + new Date(2016, 0, 9) ]; maxDate(array); // 2018-03-11T22:00:00.000Z ``` diff --git a/snippets/minDate.md b/snippets/minDate.md index 2a0c35456..23cd10e76 100644 --- a/snippets/minDate.md +++ b/snippets/minDate.md @@ -13,7 +13,7 @@ const array = [ new Date(2017, 4, 13), new Date(2018, 2, 12), new Date(2016, 0, 10), - new Date(2016, 0, 9), + new Date(2016, 0, 9) ]; minDate(array); // 2016-01-08T22:00:00.000Z ``` diff --git a/snippets/percentile.md b/snippets/percentile.md index 3522a67d8..1b2276af7 100644 --- a/snippets/percentile.md +++ b/snippets/percentile.md @@ -6,7 +6,7 @@ Use `Array.prototype.reduce()` to calculate how many numbers are below the value ```js 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; ``` ```js diff --git a/snippets/radsToDegrees.md b/snippets/radsToDegrees.md index 3cd4fa8d4..d8dd54958 100644 --- a/snippets/radsToDegrees.md +++ b/snippets/radsToDegrees.md @@ -5,7 +5,7 @@ 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; +const radsToDegrees = rad => rad * 180.0 / Math.PI; ``` ```js diff --git a/tag_database b/tag_database index 6693e7bd9..41f8e4564 100644 --- a/tag_database +++ b/tag_database @@ -131,8 +131,10 @@ intersectionWith:array,function,intermediate invertKeyValues:object,function,intermediate is:type,array,regexp,beginner isAbsoluteURL:string,utility,browser,url,intermediate +isAfterDate:date,utility,beginner isAnagram:string,regexp,intermediate isArrayLike:type,array,intermediate +isBeforeDate:date,utility,beginner isBoolean:type,beginner isBrowser:utility,browser,intermediate isBrowserTabFocused:browser,beginner @@ -150,6 +152,7 @@ isPlainObject:type,object,intermediate isPrime:math,beginner,intermediate isPrimitive:type,function,array,string,intermediate isPromiseLike:type,function,promise,intermediate +isSameDate:date,utility,beginner isSorted:array,intermediate isString:type,string,beginner isSymbol:type,beginner