Last active
November 19, 2015 07:08
-
-
Save mynameistechno/36f92b97a314e88de3a9 to your computer and use it in GitHub Desktop.
Flatten an array in Javascript
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(a) { | |
return a.reduce(function(prev, curr) { | |
if (Array.isArray(curr)) { | |
return prev.concat(flatten(curr)); | |
} | |
prev.push(curr); | |
return prev; | |
}, []); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment