Skip to content

Instantly share code, notes, and snippets.

@edrdesigner
Last active November 23, 2019 21:36
Show Gist options
  • Save edrdesigner/572b3541981f51e98f8564a73fdd54fa to your computer and use it in GitHub Desktop.
Save edrdesigner/572b3541981f51e98f8564a73fdd54fa to your computer and use it in GitHub Desktop.
export default function flatten(arr) {
return arr.reduce((flat, toFlatten) => {
return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten);
}, []);
}
// Test
flatten([[1,2,[3]],4]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment