Created
December 20, 2018 03:28
-
-
Save Zensavona/0cb1de87df4706e2f280eaba06db5a03 to your computer and use it in GitHub Desktop.
Flatten Array JS
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
const flatten = list => list.reduce( | |
(a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), [] | |
) | |
const array = [[1,2,[3]],4] | |
flatten(array) // [ 1, 2, 3, 4 ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment