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
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
}
});
}