Created
January 16, 2019 06:38
-
-
Save rmfranciacastillo/6a9abdad606c943236f8886aef8b5a02 to your computer and use it in GitHub Desktop.
Flattens an Array using JS
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
let arr = [[1,2,[3]], [[[4]]]]; | |
let flatten = arr.reduce((acc, value) => acc.concat(value), []); | |
while(flatten.some((item) => Array.isArray(item))){ | |
console.log(flatten); | |
flatten = flatten.reduce((acc, value) => acc.concat(value), []); | |
} | |
console.log(flatten) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment