-
-
Save dtmrc/418d8f06c6e08da38ca05e37dea55250 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
// Search an array for nested arrays and inline them | |
const flatten = (arr, out = []) => { | |
arr.forEach(val => { | |
if (val == null) return | |
if (Array.isArray(val)) flatten(val, out) | |
else out.push(val) | |
}) | |
return out | |
} | |
// Map an array and flatten it | |
const flatMap = (arr, mapper) => flatten(arr.map(mapper)) | |
// Filter an array to remove the given values | |
const without = (arr, ...args) => arr.filter(val => !args.includes(val)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment