Skip to content

Instantly share code, notes, and snippets.

@jamesliu96
Created September 2, 2020 06:37
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 jamesliu96/eeec6fdaefdcb97c6c104d285c1b2c03 to your computer and use it in GitHub Desktop.
Save jamesliu96/eeec6fdaefdcb97c6c104d285c1b2c03 to your computer and use it in GitHub Desktop.
export const flatten = (arr) => [].concat(...arr);
function* _flatten(arr) {
for (const item of arr) {
if (Array.isArray(item)) {
yield* _flatten(item);
} else {
yield item;
}
}
}
export const deepFlatten = (arr) => [..._flatten(arr)];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment