Skip to content

Instantly share code, notes, and snippets.

@ottonascarella
Last active December 28, 2017 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ottonascarella/171d6a23c9ca8c4fa301e1bec25e68a9 to your computer and use it in GitHub Desktop.
Save ottonascarella/171d6a23c9ca8c4fa301e1bec25e68a9 to your computer and use it in GitHub Desktop.
Flatten Array in any depth
function flatten(xs) {
return xs.reduce((acc, item) => {
if (Array.isArray(item)) {
return acc.concat(flatten(item));
}
acc.push(item);
return acc;
}, []);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment