Skip to content

Instantly share code, notes, and snippets.

@SakoMe
Created June 24, 2017 01:55
Show Gist options
  • Save SakoMe/8176d275a96c02b25f7f8a8126bfa0df to your computer and use it in GitHub Desktop.
Save SakoMe/8176d275a96c02b25f7f8a8126bfa0df to your computer and use it in GitHub Desktop.
// Functional JS to flatten an array...
const flatten = (array) => {
return array.reduce((flat, toFlatten) => {
return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten);
}, []);
}
console.log(flatten([[1,2,[3]],4]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment