Intermediate Algorithm Scripting: Steamroller code validation issue?

I got stuck doing this one so I went to the solutions and after reading through camperBot’s solutions and understanding the problem, I implemented my own solution which failed the

" Your solution should not use the Array.prototype.flat() or Array.prototype.flatMap() methods."

test, even though I did not use either of those methods. I then went back to the solutions and copied and pasted camperBot’s solutions into the sandbox to test them and for some reason, all of the official solutions, except solution #3 failed this test.

Can we see your code? And a link to the challenge?

Link to the challenge: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/steamroller

My code:

function steamrollArray(arr) {
  let results = []
  function flatten(item) {
    if(!Array.isArray(item)){
      results.push(item)
    } else {
      item.forEach(flatten)
    }
  }
  arr.forEach(flatten)
  return results
}

Link to camperBot’s solutions: http://forum.freecodecamp.org/t/freecodecamp-challenge-guide-steamroller/16079

I think the validator is checking for any variation of ‘flat’ in the code, because I changed flatten to squish and got my previous code to pass the last test.

New code:

function steamrollArray(arr) {
  let results = []
  function squish(item) {
    if(!Array.isArray(item)){
      results.push(item)
    } else {
      item.forEach(squish)
    }
  }
  arr.forEach(squish)
  return results
}
1 Like

Yeah, I think you might be right. This is the sort of thing that probably would be worth making a GitHub issue for.

1 Like

Will do! Thanks for your help

Had the same problem, the test will fail if flat or flatten appears in your code. Even if it is commented out. Just like @IamSurrett mentioned.