Created
May 29, 2019 19:46
-
-
Save aleclarson/e5228acf12f20ef1a5ac98e81f1e5040 to your computer and use it in GitHub Desktop.
This file contains 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