Flaten array of nested arrays

Tell us what’s happening:
Hi,
Sorry for disturbing you ! I know many of us asked for this challenge.
In my case, I would like to know if it’s possible to solve this challenge with filter prototype. I already tested with reduce.
How could I export my currentValue in the array to return without defining it as public like in C.

Thanks a lot!

  **Your code so far**

function steamrollArray(arr) {
let result = arr.filter( (currentValue, postion, thisArg) => {
return (!Array.isArray(currentValue)) ? currentValue /*console.log(currentValue)*/ : steamrollArray(thisArg[postion])

});

return arr;
}

console.log(steamrollArray([1, [2], [3, [[4]]]]));
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36.

Challenge: Steamroller

Link to the challenge:

It would not be ideomatic to use a filter. Filters are designed to remove items from an array.

Thanks @JeremyLT
I’ll find another without using filtering.

I don’t know how the idea of public from C is applicable here. You do not want to use global variables when you can avoid it.

Reduce is a good way to go if you want to use high order methods. You would add (in a sense) the current value to the accumulator.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.