Skip to content

Instantly share code, notes, and snippets.

@TiagoFuelber
Created November 2, 2022 23:48
Show Gist options
  • Save TiagoFuelber/b245cc9ea0e76bfdc8c662cb26c3729e to your computer and use it in GitHub Desktop.
Save TiagoFuelber/b245cc9ea0e76bfdc8c662cb26c3729e to your computer and use it in GitHub Desktop.
how to flat an array
function flatten(collection: any[]) {
return collection.reduce((result, current) => {
let value = current
if (Array.isArray(current)) {
value = flatten(current)
}
return result.concat(value)
}, [])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment