Skip to content

Instantly share code, notes, and snippets.

@bluurn
Created February 1, 2019 09:15
Show Gist options
  • Save bluurn/7282253be9a9c373204843de1684452e to your computer and use it in GitHub Desktop.
Save bluurn/7282253be9a9c373204843de1684452e to your computer and use it in GitHub Desktop.
JS: Implementation of flatten
function flatten(arr) {
return arr.reduce((acc, it) =>
acc.concat((it instanceof Array) ? flatten(it) : it)
, [])
}
flatten([[[1, [1.1]], 2, 3], [4, 5]]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment