Skip to content

Instantly share code, notes, and snippets.

@roshanca
Last active April 21, 2020 11:59
Show Gist options
  • Save roshanca/aff6cf3096b9b538c4d8e63afc2c3e22 to your computer and use it in GitHub Desktop.
Save roshanca/aff6cf3096b9b538c4d8e63afc2c3e22 to your computer and use it in GitHub Desktop.
Array flatten #js #array
/**
* @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