I thought maybe I was getting an infinite loop, because .push wasn’t reducing the length of arr., so it’s always an array. But it appears to be falling through the while loop all together… am I not checking the first index correctly?
function steamrollArray(arr) {
var R2 = [];
while (arr[0].isArray) {
console.log(arr[0]);
R2.push(arr[0]);
return R2;
}
return R2;
}
steamrollArray([[["a"]], [["b"]]]); // should return ["a", "b"].
steamrollArray([1, [2], [3, [[4]]]]); // should return [1, 2, 3, 4].
steamrollArray([1, [], [3, [[4]]]]); // should return [1, 3, 4].
steamrollArray([1, {}, [3, [[4]]]]); // should return [1, {}, 3, 4].