# Symmetric Difference does not work with more than 3 arrays

Symmetric Difference does not work with more than 3 arrays
0

#1

Guys my code does not work with more than 3 arrays.
It works for the first 2 examples but not for the rest…

function sym(args) {

args = Array.prototype.slice.call(arguments);
function symDiff(args) {
var common={};
var different ={};

var current = {};

for (var k= args[0].length-1; k>=0; k--){
current[args[0][k]] =1;
}

for (var i = args.length-1; i>=0; i--){

var curentArr = args[i];
for (var j= curentArr.length-1; j>=0; j--){

if (curentArr[j] in current) {

common[curentArr[j]] =1;
}
else {different[curentArr[j]]=-1;}

}

current = common;
common = {};

}

return Object.keys(different).map(function(value){
return parseInt(value);});
}
return(symDiff(args));
}
sym([1, 2, 3], [5, 2, 1, 4]);

https://www.freecodecamp.org/challenges/symmetric-difference

#3

If you’re after the symmetric difference of 3 sets, consider the following:

The symmetric difference is commutative and associative, so we can unambiguously write:

sym(A, B, C) = sym(sym(A, B), C)

That is to say, if we have a function that can find the symmetric difference of two sets, we can use that very same function to find the symmetric difference of three sets, by simply using it again.

See if you can figure out a way to extrapolate this to the symmetric difference of n sets. Hint: you can use reduce for this.