Created
June 22, 2017 21:06
-
-
Save mrizwanghuman/f990fd0385194e039a41c4b897c4280e to your computer and use it in GitHub Desktop.
Flatten an array of arbitrarily nested arrays
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
var unflatten =[[1,2,[3]],4] | |
let flatten = (flattenArray) => flattenArray.reduce((a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), []) | |
console.log(flatten(unflatten)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment