Steamroller javascript challenges

Tell us what’s happening:
If you were to use the spread operator on the problem the first two test wouldn’t pass, the array is flattened but yet the answer isn’t accepted. Why is that? Maybe I’m trying to take a back route to solving the problem but why doesn’t the spread operator work?

Your code so far

function steamrollArray(arr) {
  // I'm a steamroller, baby
  var returnArray = [];
  return Array(returnArray)

steamrollArray([1, [2], [3, [[4]]]]);
steamrollArray([[["a"]], [["b"]]])
steamrollArray([1, {}, [3, [[4]]]])

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36.

Link to the challenge:

What is the actual code that is failing the tests?

I’ve tried,

return [...arr]
return [...arr].join("")

What makes you think that it is flattening the array? Is there some other logic, or do you just have this?

In the console of the FCC editor the array appears flattened.
In my first test it does appear as 1,2,3,4 in the console. But now I see that it is actually not.

When you console.log an array it gets converted to a string in a way that does not show the array’s structure.

1 Like

One more question

if I were to do this

function steamrollArray(arr) {
  // I'm a steamroller, baby

  // var rArray = [1,2,3,4];

  Array.forEach(function (element, index, arr) {


steamrollArray([1, [2], [3, [[4]]]]);

Is my code iterating through the Array(arr) that is passed to the steamrollArray function?