You can not declare newArr as a global variable, because the tests run your code and keep calling the steamrollArray function multiple times. This means each time the function is called, newArr will start with the value it ended with in the previous ran test. In general, it never good to use global variables, because you never know how another part of an application may use a variable.