Last active
October 24, 2018 04:47
-
-
Save wojciak/18b661007b885912f60d8663561d4fc7 to your computer and use it in GitHub Desktop.
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
function flatten(arr) { | |
if (Array.flat) { // because we're all excited that this is finally making production! | |
return arr.flat(Infinity); | |
} | |
if (!arr.some(item => Array.isArray(item))) { | |
return arr; | |
} | |
return flatten([].concat(...arr)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment