Skip to content

Instantly share code, notes, and snippets.

@hwangar
Created August 9, 2017 18:09
Show Gist options
  • Save hwangar/c2c57cfb15e594ca8382388acb849b18 to your computer and use it in GitHub Desktop.
Save hwangar/c2c57cfb15e594ca8382388acb849b18 to your computer and use it in GitHub Desktop.
Flatten array
const a = [[1,2,[3]],4];
const flatten = list => list.reduce(
(all, elem) => all.concat(Array.isArray(elem) ? flatten(elem) : elem), []
);
console.log('------>', flatten(a));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment