Intermediate Algorithm Scripting - Steamroller

Tell us what’s happening:

Based on the output of each test, I have passed this challenge. However, I continue to fail all tests except for the one regarding using the .flat() and .flatmap() methods. I’m also failing the test for using global variables.

I need some help about why this is happening. I’m wondering if the second argument to the reduce function (“[ ]”) is perhaps triggering the global variable check? Let me know your thoughts! Thanks!

Your code so far

function flatten(arr) {
  return arr.reduce((previous, current) => {
      if (Array.isArray(current)) {
        return [...previous, ...flatten(current)]
      } else {
        return [...previous, current]
  }, [])

flatten([1, [], [3, [[4]]]])

Your browser information:

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

Challenge: Intermediate Algorithm Scripting - Steamroller

Link to the challenge:

Why did you change the name of the function?

no reason specifically. I was simply just writing code in another editor and that the was the name I gave. would this cause the issue?


Look very carefully at the test cases

steamrollArray([[["a"]], [["b"]]]) should return ["a", "b"].
steamrollArray([1, [2], [3, [[4]]]]) should return [1, 2, 3, 4]

They were written with a specific function name in mind. If you change it, then the tests fail because it wasn’t written with flatten in mind.

Hope that helps!

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