Skip to content

Instantly share code, notes, and snippets.

@bionicvapourboy
Created June 3, 2019 12:49
Show Gist options
  • Save bionicvapourboy/b535ba4fed3e5e998e6e2254338bb504 to your computer and use it in GitHub Desktop.
Save bionicvapourboy/b535ba4fed3e5e998e6e2254338bb504 to your computer and use it in GitHub Desktop.
const myArr = [[1,2,[3]],4];
const flatten = list => list.reduce(
(a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), []
);
flatten(myArr); // [1, 2, 3, 4,]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment