Skip to content

Instantly share code, notes, and snippets.

@denieler
Created October 9, 2018 22:00
Show Gist options
  • Save denieler/615e689d91b306930c5ed0b6a90fc3e4 to your computer and use it in GitHub Desktop.
Save denieler/615e689d91b306930c5ed0b6a90fc3e4 to your computer and use it in GitHub Desktop.
Array deep flatten implementation
Array.prototype.flatten = function () {
return this.reduce((list, x) => {
if (Array.isArray(x)) {
return list.concat(x.flatten())
} else {
return list.concat(x)
}
}, [])
}
[[1,2,[3]],4].flatten()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment