Skip to content

Instantly share code, notes, and snippets.

@platypusrex
Created October 15, 2015 04:20
Show Gist options
  • Save platypusrex/39d1d537773906588c16 to your computer and use it in GitHub Desktop.
Save platypusrex/39d1d537773906588c16 to your computer and use it in GitHub Desktop.
Javascript - Flatten any nested array (regardless of nesting)
function steamroller(arr) {
// I'm a steamroller, baby
arr = Array.prototype.concat.apply([], arr);
return arr.some(Array.isArray) ? steamroller(arr) : arr;
}
steamroller([1, [2], [3, [[4]]]]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment