Last active
April 7, 2019 05:27
-
-
Save singularitti/7c171c75c4d5b070d9902542ae117e01 to your computer and use it in GitHub Desktop.
Flatten multidimensional array #JavaScript #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
| function flatten(arr) { | |
| return arr.reduce(function (flat, toFlatten) { | |
| return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten); | |
| }, []); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment