Last active
May 2, 2016 23:34
-
-
Save fcarlone/df5c6cb3c42f997797968ba215ed4064 to your computer and use it in GitHub Desktop.
JavaScript - Flatten 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
var flatten = function(array) { | |
var results = []; | |
for(var i = 0; i < array.length; i++) { | |
if(Array.isArray(array[i])) { | |
results = results.concat(flatten(array[i])); | |
} else { | |
results.push(array[i]); | |
} | |
} | |
return results; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment