# Need Help With SteamRoller Algorithm

**URL:** <https://forum.freecodecamp.org/t/need-help-with-steamroller-algorithm/136339>\
**Category:** General\
**Created:** [July 15, 2017, 2:01pm UTC](https://forum.freecodecamp.org/t/need-help-with-steamroller-algorithm/136339 "2017-07-15T14:01:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdivani](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/mdivani/32/81166_2.png) [@mdivani](https://forum.freecodecamp.org/u/mdivani)\
**Post date:** [July 15, 2017, 2:01pm UTC](https://forum.freecodecamp.org/t/need-help-with-steamroller-algorithm/136339/1 "2017-07-15T14:01:17Z")

</div>

I’m doing intermediate algorithm challenge and kind of got stuck with this challenege. problem is that actually I do get correct answer for every test array but none is accepted as correct answer. I see only difference is space between array elements but is that even thing? how should I put space around numbers? please check my code and help to understand what am I doing wrong.

```
> function steamrollArray(arr) {
> // I'm a steamroller, baby
> myRecursion(arr);
> return myArr;
> }
> var myArr = [];
> function myRecursion(arr){
>   
> for(var i = 0; i < arr.length; i++){
> if(Array.isArray(arr[i])){
> myRecursion(arr[i]);
> }
> else {
> myArr.push(arr[i]);
> }
> }
> }

> steamrollArray([1, [], [3, [[4]]]]);
```

---

<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:** [July 15, 2017, 2:08pm UTC](https://forum.freecodecamp.org/t/need-help-with-steamroller-algorithm/136339/2 "2017-07-15T14:08:06Z")

</div>

Your code is correct but is not accepted because of the global variable. Revise your code so that there are no globals.

---

<div class="post-metadata">

**Author:** ![mdivani](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/mdivani/32/81166_2.png) [@mdivani](https://forum.freecodecamp.org/u/mdivani)\
**Post date:** [July 15, 2017, 2:10pm UTC](https://forum.freecodecamp.org/t/need-help-with-steamroller-algorithm/136339/3 "2017-07-15T14:10:43Z")

</div>

you sure about that? I do know global variable is not a good practice but solution with it looked so simple I just could not think of anything else even though I tried for 2 hours 🙂 so I decided to complete it like that and then go see hint and proper solution 🙂 if its all there is than I guess I will have to do it proper way myself.

---

<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:** [July 15, 2017, 2:14pm UTC](https://forum.freecodecamp.org/t/need-help-with-steamroller-algorithm/136339/4 "2017-07-15T14:14:05Z")

</div>

> [@mdivani](#):
>
> you sure about that?

It’s a pretty common problem encountered by people working on the challenges. Luckily it’s easy to remove your global variable without changing much of the code.

---

<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:48pm UTC](https://forum.freecodecamp.org/t/need-help-with-steamroller-algorithm/136339/5 "2021-01-17T20:48:10Z")

</div>

Closed on January 17, 2021, 8:48pm UTC


