Last active
November 26, 2019 10:33
-
-
Save manimal1/b6deb95f438076702085c3b759e3230b to your computer and use it in GitHub Desktop.
JavaScript utility function to flatten an array of arrays
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
export const flattenArray = (arr, depth = arr.length) => { | |
return depth > 0 | |
? arr.reduce((acc, val) => acc.concat(Array.isArray(val) ? flattenArray(val, depth - 1) : val), []) | |
: arr.slice(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment