Need help with understaning Javascript Intermediate Algorithm: Steamroller

Can someone explain to me the execution steps of the following two code? I tried a lot but I can’t seem to understand what’s going on :frowning:

function steamrollArray(arr) {
  let flat = [].concat(...arr);
  return flat.some(Array.isArray) ? steamrollArray(flat) : flat;
}

flattenArray([1, [2], [3, [[4]]]]);
function steamrollArray(arr) {
  return arr.toString()
    .replace(',,', ',')       // "1,2,,3" => "1,2,3"
    .split(',')               // ['1','2','3']
    .map(function(v) {
      if (v == '[object Object]') { // bring back empty objects
        return {};
      } else if (isNaN(v)) {        // if not a number (string)
        return v;
      } else {
        return parseInt(v);         // if a number in a string, convert it
      }
    });
}

where did you get the code from?

It’s the solution of the challenge Javascript Intermediate Algorithm: Steamroller.

there are many ways to solve this challenge. The second solution for eg uses a parsing method to flatten the array. While the first method makes a copy of the array and then checks the elements in the array to see if they are themselves arrays and if so, it calls itself to flatten these elements (utilizing something called recursion).