Last active
April 21, 2020 11:59
-
-
Save roshanca/aff6cf3096b9b538c4d8e63afc2c3e22 to your computer and use it in GitHub Desktop.
Array flatten #js #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
/** | |
* @param {Array<any>} arr | |
*/ | |
function flatten(arr) { | |
return arr.reduce((flat, toFlatten) => { | |
return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten) | |
}, []) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment