function steamroller(arr) {//1
var newArr = [];
function ude(arr){//2
while (arr.length > 0) {//3
if (Array.isArray(arr[0])) {//4
ude(arr[0]);
}//4c
else {newArr.push(arr[0]);
console.log("newArr ", newArr);
}//3c
arr.shift();
}
// I'm a steamroller, baby
return newArr;
}
return ude(arr);
}
steamroller([1, [2], [3, [[4]]]]);
On fait des fonctions emboitees pour que la variable de tableau "newArr" ne soit pas en dehors de la fonction.
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.