Dear all,
I have being trying to do my best in this exercise
steamroller exercise
I’ve been looking for a good response or how to implement the best way, the thing is that I found , that is very functional:
function steamrollArray(data) {
// our initial value this time is a blank array
const initialValue = [];
// call reduce on our data
return data.reduce((total, value) => {
// if the value is an array then recursively call reduce
// if the value is not an array then just concat our value
return total.concat(Array.isArray(value) ? steamrollArray(value) : value);
}, initialValue);
}
console.log(steamrollArray([1, [2], [3, [[4]]]]));
I understand the reduce methods because your are going one by one, but I dont do it how it gets deeper in the different arrays.
And the last one part }, initialValue);
why is this written in this way you are returning the value but why using comma.
My apologizes to everybody but I can’t understand it all then I can’t implement it for my self. If you know some resources to point out or even exercises to practice it, please let me know, I don’t want solutions, Im looking for a fishing rod.
Thanks to everybody