Created
February 1, 2017 04:27
-
-
Save the-creature/7ef4e3575c73c094219d05225590e0e8 to your computer and use it in GitHub Desktop.
es6 flat array
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 = arr => arr.reduce( | |
(a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), [] | |
); | |
testArr = [[1,2,[3]],4] | |
console.log(flatten(testArr)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment