# Steamroller Working but not passing the run test

**URL:** <https://forum.freecodecamp.org/t/steamroller-working-but-not-passing-the-run-test/152380>\
**Category:** General\
**Created:** [October 10, 2017, 9:55am UTC](https://forum.freecodecamp.org/t/steamroller-working-but-not-passing-the-run-test/152380 "2017-10-10T09:55:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pranav-kural](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pranav-kural/32/161190_2.png) [@pranav-kural](https://forum.freecodecamp.org/u/pranav-kural)\
**Post date:** [October 10, 2017, 9:55am UTC](https://forum.freecodecamp.org/t/steamroller-working-but-not-passing-the-run-test/152380/1 "2017-10-10T09:55:03Z")

</div>

**Tell us what’s happening:**  
Here’s my solution and it does work (for all the cases as given on FreeCodeCamp for this challenge), but when I run to test it, it doesn’t pass. I’ve tried all the following cases, and it does return the right values, but none of the tests pass when I run test on FreeCodeCamp.

steamrollArray([[[“a”]], [[“b”]]]) should return [“a”, “b”].  
steamrollArray([1, [2], [3, [[4]]]]) should return [1, 2, 3, 4].  
steamrollArray([1, , [3, [[4]]]]) should return [1, 3, 4].  
steamrollArray([1, {}, [3, [[4]]]]) should return [1, {}, 3, 4].

**Your code so far**

```auto
let vals = [];

function steamrollArray(arr) {
  
  arr.forEach((val) => {
    if (Array.isArray(val)){
      steamrollArray(val);
    } else {
      vals.push(val);
    }
  });
  
  return vals;
}

steamrollArray([[["a"]], [["b"]]]);

```

**Your browser information:**

Your Browser User Agent is: `Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.86`.

**Link to the challenge:**  
[https://www.freecodecamp.org/challenges/steamroller](https://www.freecodecamp.org/challenges/steamroller)

---

<div class="post-metadata">

**Author:** ![kevcomedia](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kevcomedia/32/125737_2.png) [@kevcomedia](https://forum.freecodecamp.org/u/kevcomedia)\
**Post date:** [October 10, 2017, 10:41am UTC](https://forum.freecodecamp.org/t/steamroller-working-but-not-passing-the-run-test/152380/2 "2017-10-10T10:41:52Z")

</div>

Challenges generally won’t pass if you used global variables.

You’ll have to do a bit of rewrite so your code doesn’t use globals.

---

<div class="post-metadata">

**Author:** ![pranav-kural](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pranav-kural/32/161190_2.png) [@pranav-kural](https://forum.freecodecamp.org/u/pranav-kural)\
**Post date:** [October 10, 2017, 11:39am UTC](https://forum.freecodecamp.org/t/steamroller-working-but-not-passing-the-run-test/152380/3 "2017-10-10T11:39:53Z")

</div>

Yeah I thought so, using global variables might not be an appropriate solution, but I guess then there should be a note (or a condition) on that on the challenge page. (because otherwise the solution still meets all conditions specified by FCC.) Anyways, thanks though.

This worked for me:

```auto
function steamrollArray(...arr) {
  
  let vals = arr[1] ? arr[1] : []; 
  
  arr[0].forEach((val) => {
    if (Array.isArray(val)){
      console.log(vals);
      steamrollArray(val, vals);
    } else {
      vals.push(val);
    }
  });
  
  return vals;
}

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

```

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 17, 2021, 8:37pm UTC](https://forum.freecodecamp.org/t/steamroller-working-but-not-passing-the-run-test/152380/4 "2021-01-17T20:37:53Z")

</div>


