loading
open in
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function steamrollArray(arr) {
  function flatten(item){

    if(Array.isArray(item)){
      console.log("found this array: " + item);
      for (let a in item) {
        console.log("a is " + a);
        console.log("try to flatten this: " + item[a]);
        return flatten(item[a]);
      }
    } else { 
       return item;
    }
  }
  console.log("apply flatten to all the items in the given array:" + arr);
  console.log(arr.map(flatten));
  return arr.map(flatten);
}

steamrollArray([1, [2], [3, [[4]]]]);
node v10.15.2 linux/amd64