# Intermediate Algorithm Scripting ,Steamroller problem is solved with map but does not work

**URL:** <https://forum.freecodecamp.org/t/intermediate-algorithm-scripting-steamroller-problem-is-solved-with-map-but-does-not-work/161067>\
**Category:** General\
**Created:** [November 27, 2017, 11:12am UTC](https://forum.freecodecamp.org/t/intermediate-algorithm-scripting-steamroller-problem-is-solved-with-map-but-does-not-work/161067 "2017-11-27T11:12:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sifatul](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/sifatul/32/70763_2.png) [@Sifatul](https://forum.freecodecamp.org/u/Sifatul)\
**Post date:** [November 27, 2017, 11:13am UTC](https://forum.freecodecamp.org/t/intermediate-algorithm-scripting-steamroller-problem-is-solved-with-map-but-does-not-work/161067/1 "2017-11-27T11:13:00Z")

</div>

```auto
var str=[];
function steamrollArray(arr) {
 
 
 arr.map(function(a){
 			if(Array.isArray(a)){
      	str=steamrollArray(a);
      }else{
      	str.push(a);
      }
 });
 
 return str;
}

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

```

Can someone help me understand why this answer is wrong?

---

<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:** [November 27, 2017, 11:18am UTC](https://forum.freecodecamp.org/t/intermediate-algorithm-scripting-steamroller-problem-is-solved-with-map-but-does-not-work/161067/2 "2017-11-27T11:18:34Z")

</div>

Solutions that use global variables generally don’t work in the challenges. You’ll have to rewrite your code so that there are no globals.

---

<div class="post-metadata">

**Author:** ![Sifatul](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/sifatul/32/70763_2.png) [@Sifatul](https://forum.freecodecamp.org/u/Sifatul)\
**Post date:** [November 27, 2017, 11:35am UTC](https://forum.freecodecamp.org/t/intermediate-algorithm-scripting-steamroller-problem-is-solved-with-map-but-does-not-work/161067/3 "2017-11-27T11:35:55Z")

</div>

Opps! I did not know that! Thank you! 🙂

---

<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:33pm UTC](https://forum.freecodecamp.org/t/intermediate-algorithm-scripting-steamroller-problem-is-solved-with-map-but-does-not-work/161067/4 "2021-01-17T20:33:49Z")

</div>

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


