your answer is not correct. you have a global variable, that means that every time the function is called (and for the tests it is called many times), new items are added there. only the first function call will have correct result, the others will have other items at the beginning of tre array
That’s fine, but steamrollArray only takes a single argument, so you have to provide a default else it won’t work (i.e. steamrollArray (arr, requiredArray = []) {). Then you can use requiredArray in subsequent recursive calls. And you’ll likely have to rethink how your loop works and what you’re returning.
You can also do the following. Your current code:
var requiredArray = []
function steamrollArray(arr) {
// do stuff
}
to:
function steamrollArray(arr) {
var requiredArray = []
function originalSteamrollArray(arr) {
// do stuff
}
originalSteamrollArray(arr);
}