Created
January 13, 2018 19:17
-
-
Save developeron29/cebcbd2df45a29ebe3d97ae306505ce2 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 flattenArray(final, main, i) { | |
if(main[i] instanceof Array) { | |
flattenArray(final, main[i], 0) | |
} else { | |
flatArray.push(main[i]); | |
} | |
if(main.length !== (i + 1)) { | |
flattenArray(final, main, (i + 1)) | |
} | |
} | |
var nestedArray = [[1,2,[3]],4]; | |
var flatArray = []; | |
flattenArray(flatArray, nestedArray, 0) | |
console.log(flatArray); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment