1const steamrollArray = (arr, finalArr = []) => {
2 arr.forEach(elem => {
3 if(Array.isArray(elem)){
4 steamrollArray(elem, finalArr)
5 }
6 else{
7 finalArr.push(elem)
8 }
9 });
10
11 return finalArr
12}
13
14const ans = steamrollArray([1, [], [3, [[4]]]]);
15console.log(ans)