Skip to content

Instantly share code, notes, and snippets.

@vi2co
Created July 26, 2019 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vi2co/c58f362c3d3d5fee19f7b230ef4ca14b to your computer and use it in GitHub Desktop.
Save vi2co/c58f362c3d3d5fee19f7b230ef4ca14b to your computer and use it in GitHub Desktop.
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