Last active
January 3, 2019 06:37
-
-
Save matthieu-foucault/2de97857d642fa45d408a0fb09640e10 to your computer and use it in GitHub Desktop.
Flatten function
This file contains 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
const flatten = (array) => { | |
const result = []; | |
for (e of array) { | |
if (Array.isArray(e)) { | |
for (ee of flatten(e)) { | |
result.push(ee); | |
} | |
} else { | |
result.push(e); | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment