Last active
February 4, 2017 22:02
-
-
Save helloncanella/37513ad64b62e37c161c7b7f0bebb9ae to your computer and use it in GitHub Desktop.
flatten an 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
function flatten(A) { | |
let flattened = [] | |
A.forEach(item => { | |
if (Array.isArray(item)) item = flatten(item) | |
flattened = flattened.concat(item) | |
}) | |
return flattened | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment