Created
June 23, 2021 12:21
-
-
Save wperron/40206337d4da6eb3ef3e30550620cb69 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// includes-all | |
needles.map((elem) => haystack.includes(elem)).reduce((found, curr) => found && curr); | |
// includesAny | |
needles.some((elem) => haystack.includes(elem)); | |
// includesNone | |
!needles.some((elem) => haystack.includes(elem)); | |
// mapNotNullish | |
arr.filter(i => i).map(() => {}); | |
// takeFirstWhile | |
firsts = original.slice(original.findIndex((i) => {})); | |
// takeLastWhile | |
lasts = original.slice(original.findIndex((i) => {}) - original.length); | |
// dropFirstWhile & dropLastWhile are just aliases for the previous 2 | |
// sortBy | |
arr.sort((a, b) => a.age < b.age); | |
// without | |
arr.filter((n) => n !== 13); | |
// withoutAll | |
arr.filter((n) => !needles.includes(n)); | |
// firstNotNullishOf | |
arr.filter(i => i)[0]; | |
// sumOf | |
arr.reduce((accumulator, current) => accumulator += current.age); | |
// maxBy & minBy | |
arr.reduce((accumulator, current) => { | |
if (accumulator.age < current.age) { | |
accumulator = current; | |
} | |
}); | |
// maxWith & minWith | |
let numbers = [ | |
[ 1, 3, 4 ], | |
[ 6, 1, 3 ], | |
[ 4, 5, 2 ], | |
]; | |
const sum = (acc, curr) => acc += curr; | |
arr.reduce((accumulator, current) => { | |
if (accumulator.reduce(sum) < current.reduce(sum)) { | |
accumulator = current; | |
} | |
}); | |
// maxOf & minOf | |
arr.reduce((accumulator, current) => accumulator = Math.max(accumulator, current.age)); | |
// average | |
arr.reduce((accumulator, current) => accumulator += current) / arr.length; | |
// associateBy | |
arr.map((i) => { | |
return { i.id: i }; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment