Last active
December 28, 2017 04:28
-
-
Save ottonascarella/171d6a23c9ca8c4fa301e1bec25e68a9 to your computer and use it in GitHub Desktop.
Flatten Array in any depth
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
function flatten(xs) { | |
return xs.reduce((acc, item) => { | |
if (Array.isArray(item)) { | |
return acc.concat(flatten(item)); | |
} | |
acc.push(item); | |
return acc; | |
}, []); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment