Skip to content

Instantly share code, notes, and snippets.

@gabrielem
Created September 17, 2016 20:02
Show Gist options
  • Save gabrielem/5c3a543e1f0999e33b2242ee6643fcb3 to your computer and use it in GitHub Desktop.
Save gabrielem/5c3a543e1f0999e33b2242ee6643fcb3 to your computer and use it in GitHub Desktop.
FlattenArray - For careers.citrusbyte.com
function flatten(arr) {
const flat = [].concat(...arr)
return flat.some(Array.isArray) ? flatten(flat) : flat;
}
/*
Usage:
*/
flatten([[1,2,[3]],4])
/*
Result:
[1, 2, 3, 4]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment