Skip to content

Instantly share code, notes, and snippets.

@arnonate
Created September 18, 2020 19:28
Show Gist options
  • Save arnonate/e3cfb28291d89ac6a7ce6fc07663614a to your computer and use it in GitHub Desktop.
Save arnonate/e3cfb28291d89ac6a7ce6fc07663614a to your computer and use it in GitHub Desktop.
// Flatten an Array of Arrays without using .flat()
function flatten(array) {
return array.reduce((acc, item) => {
if (Array.isArray(item)) {
acc = acc.concat(flatten(item));
} else {
acc.push(item);
}
return acc;
}, []);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment