Last active
May 19, 2016 02:11
-
-
Save lai32290/10f4fcf9555212ee9911c8a15b3789a3 to your computer and use it in GitHub Desktop.
Array Flat
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
Array.prototype.flat = function () { | |
var result = []; | |
this.forEach(function (item) { | |
if (Array.isArray(item)) { | |
result = result.concat(item.flat()); | |
return; | |
} | |
result.push(item); | |
}); | |
return result; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment