```
function steamrollArray(arr) {
// I'm a steamroller, baby
var flatArr = [];
for (var x = 0; x < arr.length; x++) {
if (Array.isArray(arr[x])) {
// if item from arr is array
flatArr = flatArr.concat(steamrollArray(arr[x]));
// recursively flatten array
}
else {
flatArr.push(arr[x]);
// push array items, non-arrays etc, to flatArr
}
}
return flatArr;
}
steamrollArray([1, [2], [3, [[4]]]]);
```

Hi all

Can anyone explain this code to me

paticularly this line

flatArr = flatArr.concat(steamrollArray(arr[x]));

For example, with the test, steamrollArray([1, [2], [3, [[4]]]]);

what would be the ouput of flatArr if you where to log it after each recursive function call?

how exactly does the alrgorithm go from [1, [2], [3, [[4]]]] to [1,2,3,4]?