Skip to content

Instantly share code, notes, and snippets.

@kojilab
Created November 30, 2017 03:36
Show Gist options
  • Save kojilab/955eb5167fe9cff813a4ded82126306d to your computer and use it in GitHub Desktop.
Save kojilab/955eb5167fe9cff813a4ded82126306d to your computer and use it in GitHub Desktop.
JS Array.flatten
Array.prototype.flatten = function() {
return this.reduce(function(acc, v) {
if (!Array.isArray(v)) {
acc.push(v)
} else {
acc = acc.concat(v.flatten())
}
return acc;
}, [])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment