Created
October 9, 2018 22:00
-
-
Save denieler/615e689d91b306930c5ed0b6a90fc3e4 to your computer and use it in GitHub Desktop.
Array deep flatten implementation
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((list, x) => { | |
if (Array.isArray(x)) { | |
return list.concat(x.flatten()) | |
} else { | |
return list.concat(x) | |
} | |
}, []) | |
} | |
[[1,2,[3]],4].flatten() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment