Intermediate Algorithm challenge - Steamroller

Intermediate Algorithm challenge - Steamroller
0

#1

Hi camper, I’m having trouble completing this challenge. I’ve tried implementing Steamroller challenge through recursion and it seems that it won’t let me advance into the next challenge. Here’s the code:

function steamrollArray(arr) {
  // I'm a steamroller, baby
  function flattenArray(arr){
    if(!Array.isArray(arr)) return arr;
    
    return flattenArray(arr.reduce(x => flattenArray(x)));
  }

  return arr.map(x => flattenArray(x));
}

let test = steamrollArray([1, [2], [3, [[4]]]]);
console.log(test);  

#2

I think you may not really understand recursion yet.
To debug this algorithm, add console.log statements before and after each line and log each variable.
Review that carefully and refine your algorithm based on what you find.
Update your code once you’ve made that initial effort. I think you will probably find the issue quite quickly.