Last active
August 2, 2019 14:44
-
-
Save welingtonms/0856e912d75456ec5dd86ff28c79f341 to your computer and use it in GitHub Desktop.
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(array) { | |
let flattened = []; | |
for (let i = 0; i < array.length; i++) { | |
if (Array.isArray(array[i])) { | |
flattened = flattened.concat(flatten(array[i])) | |
} else { | |
flattened.push(array[i]) | |
} | |
} | |
return flattened; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment