SteamRoller | FCC not accepting any of the test cases

Hello I wanted to use recursion for the Steam roller question in Intermediate Algorithm Scripting section.
I created a global array variable named result and created it above the function (so it would be global).

My code works perfectly in jsfiddle.net and on vs Code but freecodecamp is not accepting even one of the provided test cases.

Please not that all the test cases are passing in jsfiddle.net and are returning the array as mentioned on FCC.

Here is the code:

var result = [];

function steamrollArray(arr) {
    // I'm a steamroller, baby
    var temp;
    for (var i = 0; i < arr.length; i++) {
      if (!Array.isArray(arr[i]))
        result.push(arr[i]);
      else
        steamrollArray(arr[i]);  
    }
  console.log(result);
  return result;
}

steamrollArray([1, {}, [3, [[4]]]]);

This won’t work because of the global variable. So it will work for one test case, so for example for steamrollArray([1, {}, [3, [[4]]]]) you end up with [1, {}, 3, 4]. But now result is [1, {}, 3, 4], so next test you push more values into result - so for steamrollArray([1, [2], [3, [[4]]]]), you get [1, {}, 3, 4, 1, 2, 3, 4], and so on.