Skip to content

Instantly share code, notes, and snippets.

@romucci
Created July 6, 2018 03:40
Show Gist options
  • Save romucci/110954ee6bf41930a22726ed1f160027 to your computer and use it in GitHub Desktop.
Save romucci/110954ee6bf41930a22726ed1f160027 to your computer and use it in GitHub Desktop.
Flatten Array - Lucas Otero
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