Code worked for every test result but cannot past tests

Tell us what’s happening:
Every test I had experimented worked, but the test just can’t be passed.

Here is my code:

function uniteUnique(arr1, arr2, arr3) {
 
for (var i = 0; i < arguments.length; i++) {
  var arrayArguments = arguments[i]
}
var firstArr = [...arguments[0]]
for (let i = 1; i < arguments.length; i++){
  arrD (firstArr, arguments[i])
}
var brandNewArr = firstArr.concat(diffArr)
return brandNewArr
}

function arrD (arr1, arr2){
var newAr1 = [...arr1]
var newAr2 = [...arr2]
var simArr= []
for (let i = 0; i < newAr1.length; i++){
  for (let j = 0; j < newAr2.length; j++){
    if (newAr1[i] == newAr2[j]){
      simArr.push(newAr2[j])
    } 
  }
}

if (simArr[0] == undefined){
  for (let i = 0; i < newAr2.length; i++){
    diffArr.push(newAr2[i])
  }
  return newAr1
} else {
  for (let k = 0; k < simArr.length; k++){
    var newArr = removeItemAll(newAr2, simArr[k])
  }

  for (let i = 0; i < newArr.length; i++){
    newAr1.push(newArr[i])
    diffArr.push(newArr[i])
  }
 return diffArr
}
}

function removeItemAll(arr1, value) {
var i = 0;
while (i < arr1.length) {
  if (arr1[i] === value) {
    arr1.splice(i, 1);
  } else {
    ++i;
  }
}
return arr1; 
}

var diffArr = [] 

console.log(uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]));

My browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36.

Challenge: Sorted Union

Link to the challenge:

Welcome to the forums.

When I copy your code in the challenge

and add the other tests

console.log(uniteUnique([1, 2, 3], [5, 2, 1]));
console.log(uniteUnique([1, 2, 3], [5, 2, 1, 4], [2, 1], [6, 7, 8]));

the output is

[ 1, 3, 2, 5, 4 ]
[ 1, 2, 3, 5, 4, 5 ]
[ 1, 2, 3, 5, 4, 5, 5, 4, 6, 7, 8 ]

which is not the expected output. The problem is most likely

which is global and not reset between function calls, which leads to the output above. The same thing is happening when the tests run; diffArr gets assigned a value on the first function call, gets modified on the second, etc. I would try to find a way to create the function without a array outside the function.