Skip to content

Instantly share code, notes, and snippets.

@helloncanella
Last active February 4, 2017 22:02
Show Gist options
  • Save helloncanella/37513ad64b62e37c161c7b7f0bebb9ae to your computer and use it in GitHub Desktop.
Save helloncanella/37513ad64b62e37c161c7b7f0bebb9ae to your computer and use it in GitHub Desktop.
flatten an array
function flatten(A) {
let flattened = []
A.forEach(item => {
if (Array.isArray(item)) item = flatten(item)
flattened = flattened.concat(item)
})
return flattened
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment