Created
May 22, 2019 01:08
-
-
Save jadeallencook/8441a399627e10c17a805386d92c0db9 to your computer and use it in GitHub Desktop.
Recursive ES6 function that flattens an array.
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
const flatten = array => array.reduce((temp, value) => temp.concat(Array.isArray(value) ? flatten(value) : value), []); | |
// example | |
console.log(flatten([[['str']],undefined,null,{},[[true,false],[{},[]],[],{}],[],[],[],[]])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment