Created
May 13, 2015 19:12
-
-
Save hamiltondanielb/0a9352879c4ed2ebb399 to your computer and use it in GitHub Desktop.
ES6 array Flatten to ES5 (reduce)
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
Array.prototype.flatten = Array.prototype.flatten || function() { | |
var flattened = []; | |
for (var i = 0; i < this.length; ++i) { | |
if (Array.isArray(this[i])) { | |
flattened = flattened.concat(this[i].flatten()); | |
} else { | |
flattened.push(this[i]); | |
} | |
} | |
return flattened; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment