Symmetric Difference: Can't see what's wrong [SOLVED]

I am a little bit confused here.
My code returns all arrays that should be returned but when it comes to the number of the elements, some arrays pass the test and some don’t.
As far as I can see, it happens when there are more than one of the same number in an array.
I will be grateful for any help.

function sym(args) {
  var symmDiffArr = [];
  for(var k = 0; k < arguments.length; k++){
  var symArr = symmDiffArr.reduce(function(a, b){
  var newArr = [];  
 for(var i = 0; i < a.length; i++){
   if(b.indexOf(a[i])===-1 && newArr.indexOf(a[i]===-1)){
  for(var j = 0; j < b.length; j++){
    if(a.indexOf(b[j])===-1 && newArr.indexOf(b[j]===-1)){
  return newArr;

  return symArr;

Pay attention to second condition, what is the argument of indexOf?
Is it a[i] or a[i] === -1. Same mistake appears in your second if statement as well.

1 Like

Thank you very much for your replay. I see that the second condition is not good but I think that the element that is already in the newArr shouldn’t be pushed. I can’t focus because all I see is that every returned array has exact number of the elements…
I was typing this replay, feeling sorry for myself than it clicked! I finally understood what you had suggested. I put those parenthesis where they belong and my code past all tests.
Much obliged.