Created
July 26, 2019 18:47
-
-
Save vi2co/c58f362c3d3d5fee19f7b230ef4ca14b 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
let arr = [1,[6,7],3,[1,2,3,4, [2,3,4]]]; | |
function unfoldArray(arr) { | |
let arrNew = []; | |
for (let i = 0; i < arr.length; i++) { | |
if (arr[i].length === undefined) { | |
arrNew.push(arr[i]); | |
} else { | |
arrNew = arrNew.concat(unfoldArray(arr[i])); | |
} | |
} | |
return arrNew; | |
} | |
console.log(unfoldArray(arr)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment