Hello,
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.
Cheers!
function sym(args) {
var symmDiffArr = [];
for(var k = 0; k < arguments.length; k++){
symmDiffArr.push(arguments[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)){
newArr.push(a[i]);
}
}
for(var j = 0; j < b.length; j++){
if(a.indexOf(b[j])===-1 && newArr.indexOf(b[j]===-1)){
newArr.push(b[j]);
}
}
return newArr;
});
return symArr;
}