Created
July 6, 2018 03:40
-
-
Save romucci/110954ee6bf41930a22726ed1f160027 to your computer and use it in GitHub Desktop.
Flatten Array - Lucas Otero
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 array = [[1,2,[3]],4] | |
let newArray = [] | |
const FlattenArray = array => { | |
for (let i = 0; i < array.length; i++) { | |
typeof array[i] === 'object' ? FlattenArray(array[i]) : newArray.push(array[i]) | |
} | |
return newArray | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment