Here is my solution to a coding challenge on FreeCodeCamp called "Symmetric Difference."
I'm puzzled as to why my code is returning 2, 3, 4, 6 instead of the expected 2, 3, 4, 6, 7.
function sym(args) {
args = Array.from(arguments);
var newArr = [];
function removeFirstIndex() {
for (var i = 0; i <= args[1].length; i++) {
if (args[1].indexOf(args[0][i]) === -1) {
newArr.push(args[0][i]);
}
if (args[0].indexOf(args[1][i]) === -1) {
newArr.push(args[1][i]);
}
}
args = args.splice(2);
args.unshift(newArr);
newArr=[];
}
while (args.length>1){
removeFirstIndex();
}
args=args.reduce(function(a,b){
return a.concat(b);
});
args=args.filter(function(elem,pos,self){
return self.indexOf(elem)===pos && elem!==undefined;
});
return args.sort();
}
sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3]); // should return 2, 3, 4, 6, 7