Algorithms: Find the Symmetric Difference

function sym(...args) {
  console.log(args);
  console.log(args.length);
  var k =0
  while(k!=1){
    var arr4 = compare(args[0],args[1])
    args= args.slice(2)
    k++
  }
  return arr4.sort()
}
function compare(arr1,arr2){
  var arr3=[]
  arr3=arr1
  arr3=arr3.concat(arr2)
  
console.log('begin array: '+arr3)
  for(i=0;i<arr3.length;i++){
    for(j=i+1;j<arr3.length;j++){
      if(arr3[i]==arr3[j]){
        arr3.splice(j,1)
        arr3.splice(i,1)
        i=-1
        break;
      }
    }
  }
  return arr3
}

sym([1, 2, 3], [5, 2, 1, 4]) 

Hi I’m not sure what’s wrong with my code? for the problem set: ’ Algorithms: Find the Symmetric Difference’

First, make sure you always declare any variables used. You currently have not declared two variables (see your for loops).

Second, what is the purpose of assigning -1 to i in the following code?

  for(i=0;i<arr3.length;i++){
    for(j=i+1;j<arr3.length;j++){
      if(arr3[i]==arr3[j]){
        arr3.splice(j,1)
        arr3.splice(i,1)
        i=-1
        break;
      }
    }
  }