Skip to content

Instantly share code, notes, and snippets.

@supernoveau
Created May 25, 2016 16:29
Show Gist options
  • Save supernoveau/35c73773b0493d17384166eb52bd56b5 to your computer and use it in GitHub Desktop.
Save supernoveau/35c73773b0493d17384166eb52bd56b5 to your computer and use it in GitHub Desktop.
function flatten(arr) {
return arr.reduce( (flat, toFlatten) => {
return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten);
}, []);
}
console.log( flatten([[1,2,[3]],4]) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment