Created
December 11, 2018 11:32
-
-
Save jasperblues/383283c0f295439bf4234e1f00bbeaba to your computer and use it in GitHub Desktop.
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 flatten = arr => arr.reduce( | |
(a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), [] | |
); | |
flatten([[1, 2, [3]], 4]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If the array arrays are not nested we can just use the spread operator: