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