Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vasylpb/b683a147a0b1aab924fecadadab058fd to your computer and use it in GitHub Desktop.
Save vasylpb/b683a147a0b1aab924fecadadab058fd to your computer and use it in GitHub Desktop.
concat nested arrays
// [1, [1, 2, [3, 4]], [2, 4]] -> [1, 1, 2, 3, 4, 2, 4]
const flatten = (arr) => arr.reduce((flat, toFlatten) => flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten), []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment