Skip to content

Instantly share code, notes, and snippets.

@welingtonms
Last active August 2, 2019 14:44
Show Gist options
  • Save welingtonms/0856e912d75456ec5dd86ff28c79f341 to your computer and use it in GitHub Desktop.
Save welingtonms/0856e912d75456ec5dd86ff28c79f341 to your computer and use it in GitHub Desktop.
function flatten(array) {
let flattened = [];
for (let i = 0; i < array.length; i++) {
if (Array.isArray(array[i])) {
flattened = flattened.concat(flatten(array[i]))
} else {
flattened.push(array[i])
}
}
return flattened;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment