# Steamroller, code not passing any tests

**URL:** <https://forum.freecodecamp.org/t/steamroller-code-not-passing-any-tests/310738>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [August 31, 2019, 5:29am UTC](https://forum.freecodecamp.org/t/steamroller-code-not-passing-any-tests/310738 "2019-08-31T05:29:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gabrieljim](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/gabrieljim/32/109652_2.png) [@gabrieljim](https://forum.freecodecamp.org/u/gabrieljim)\
**Post date:** [August 31, 2019, 5:29am UTC](https://forum.freecodecamp.org/t/steamroller-code-not-passing-any-tests/310738/1 "2019-08-31T05:29:35Z")

</div>

**Tell us what’s happening:**  
Hey everyone! My code works for me, and it’s logging the proper thing to the console too, however it’s not passing any of the FCC tests, I wonder what I’m doing wrong?  
Thanks a lot in advance!

**Your code so far**

```js

function nest(el) {
	if (!Array.isArray(el)) {
		return el;
	}
	return nest(el[0]);
}

let newArr = [];

function steamrollArray(arr) {
  arr.forEach( (el) => {
	  if (!Array.isArray(el)) { 
		  newArr.push(nest(el));
	  }
	  else {
		  el.forEach(el => { 
			  newArr.push(nest(el));
		  })
	  }
  })
  return newArr;
}

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

```

**Your browser information:**

User Agent is: `Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/75.0.3770.90 Chrome/75.0.3770.90 Safari/537.36`.

**Link to the challenge:**

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/steamroller)**
>
> Learn to Code — For Free

---

<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:** [August 31, 2019, 6:12am UTC](https://forum.freecodecamp.org/t/steamroller-code-not-passing-any-tests/310738/2 "2019-08-31T06:12:24Z")

</div>

Your code contains global variables that are changed each time the function is run. This means that after each test completes, subsequent tests start with the previous value. To fix this, make sure your function doesn’t change any global variables, and declare/assign variables within the function if they need to be changed.

Example:

```javascript
var myGlobal = [1];
function returnGlobal(arg) {
  myGlobal.push(arg);
  return myGlobal;
} // unreliable - array gets longer each time the function is run

function returnLocal(arg) {
  var myLocal = [1];
  myLocal.push(arg);
  return myLocal;
} // reliable - always returns an array of length 2

```

---

<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 25, 2021, 12:17pm UTC](https://forum.freecodecamp.org/t/steamroller-code-not-passing-any-tests/310738/3 "2021-01-25T12:17:34Z")

</div>

Closed on January 25, 2021, 12:17pm UTC


