Created
August 9, 2017 18:09
-
-
Save hwangar/c2c57cfb15e594ca8382388acb849b18 to your computer and use it in GitHub Desktop.
Flatten array
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
const a = [[1,2,[3]],4]; | |
const flatten = list => list.reduce( | |
(all, elem) => all.concat(Array.isArray(elem) ? flatten(elem) : elem), [] | |
); | |
console.log('------>', flatten(a)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment