Created
May 5, 2019 15:31
-
-
Save vasylpb/b683a147a0b1aab924fecadadab058fd to your computer and use it in GitHub Desktop.
concat nested arrays
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
// [1, [1, 2, [3, 4]], [2, 4]] -> [1, 1, 2, 3, 4, 2, 4] | |
const flatten = (arr) => arr.reduce((flat, toFlatten) => 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