Created
November 30, 2017 03:36
-
-
Save kojilab/955eb5167fe9cff813a4ded82126306d to your computer and use it in GitHub Desktop.
JS Array.flatten
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.flatten = function() { | |
return this.reduce(function(acc, v) { | |
if (!Array.isArray(v)) { | |
acc.push(v) | |
} else { | |
acc = acc.concat(v.flatten()) | |
} | |
return acc; | |
}, []) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment