Created
December 31, 2017 06:30
-
-
Save DAB0mB/6c038caafa914998b0a1be1ae525040e to your computer and use it in GitHub Desktop.
A JavaScript function to flat an array recursively
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
function flattenDeep(array) { | |
if (!(array instanceof Array)) { | |
return array; | |
} | |
return array.reduce((flatArray, cell) => { | |
return flatArray.concat(flattenDeep(cell)); | |
}, []); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment