3 questions
-
For set sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]) should return [1, 4, 5].; Why is 5 in it? I do understand that 1 and 4 are rather unique in their sets
-
Is there a way to run through all your code and see exactly what is happening per phase with example values? I could do console.log everywhere but I remember a tool that really showed what was happening? Because;
-
I have the idea that the result of “uniqueVals” in the first example is [3,5,4]. Therefore, I don’t understand that reducing the “total” argsArray with something that in my eyes is the final result does give the final right result (in my eyes it should give the opposite or in other words; reducing the full array with the wrong values should give the right result). Apparently I don’t understand reducing good enough…
Feeling me ?
Please help!!
Your code so far
function sym(args) {
var argsArray = [].slice.call(arguments);
function symDiff(arr1,arr2){
var uniqueVals = [];
for(var i = 0; i<arr1.length; i++){
if(arr2.indexOf(arr1[i])<0 && uniqueVals.indexOf(arr1[i])<0){
uniqueVals.push(arr1[i]);
}
}
arr2.forEach(function(item){
if(arr1.indexOf(item)<0 && uniqueVals.indexOf(item)<0){
uniqueVals.push(item);
}
});
return uniqueVals;
}
return argsArray.reduce(symDiff);
}
sym([1, 2, 3], [5, 2, 1, 4]);
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36
.
Link to the challenge:
https://www.freecodecamp.org/challenges/symmetric-difference