Created
November 17, 2015 20:54
-
-
Save Lee182/a64ff2eb3d142421b518 to your computer and use it in GitHub Desktop.
Want to flatten that array, here's a recurrsive way to do that
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) { | |
var ans = [] | |
arr.forEach(function(ar){ | |
if ( Array.isArray(ar) ) { ans = ans.concat( flatten(ar) ) } | |
else { ans.push(ar) } | |
}) | |
return ans | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment