Created
November 2, 2022 23:48
-
-
Save TiagoFuelber/b245cc9ea0e76bfdc8c662cb26c3729e to your computer and use it in GitHub Desktop.
how to flat an array
This file contains 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 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