Skip to content

Instantly share code, notes, and snippets.

@iamvanja
Created February 21, 2017 03:23
Show Gist options
  • Save iamvanja/f035e3fabd27d25578eeb16740664b63 to your computer and use it in GitHub Desktop.
Save iamvanja/f035e3fabd27d25578eeb16740664b63 to your computer and use it in GitHub Desktop.
Flatten array
var flatten = function(arr) {
return arr.reduce(function (flat, toFlatten) {
return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten);
}, []);
}
flatten([[1,2,[3]],4]); // [1,2,3,4]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment