Created
September 17, 2016 20:02
-
-
Save gabrielem/5c3a543e1f0999e33b2242ee6643fcb3 to your computer and use it in GitHub Desktop.
FlattenArray - For careers.citrusbyte.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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