Last active
April 28, 2018 03:49
-
-
Save nelsonomuto/ddf26ae5582ceaa5065478867d60491b 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
(function flatten(arr, currentIndex = 0, flattened = []) { | |
let currItem; | |
if (currentIndex >= arr.length) { | |
return flattened; | |
} | |
currItem = arr[currentIndex++]; | |
if (!Array.isArray(currItem)) { | |
flattened.push(currItem); | |
} else { | |
flattened = flattened.concat(flatten(currItem)); | |
} | |
return flatten(arr, currentIndex, flattened); | |
})([[43,[5,6],7], 10]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment