Created
March 5, 2014 20:33
-
-
Save extrabacon/9375999 to your computer and use it in GitHub Desktop.
Flattening 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 flattenArray(array) { | |
var results = []; | |
var self = arguments.callee; | |
array.forEach(function(item) { | |
Array.prototype.push.apply(results, Array.isArray(item) ? self(item) : [item]); | |
}); | |
return results; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment