Tell us what’s happening:
Describe your issue in detail here.
Can somebody explain why the test comparing elements in the second array passed into this function as args, if ((arguments[1][i] in arguments[0]) === false),
works by adding [5, 4] to symDif1 while the other test , ((arguments[0][i] in arguments[1]) === false) creates an empty array ? The contents of both arguments[0] and arguments[1] are identical for both if statements, but the comparison of the first array to the second produces an empty array instead of [3] as expected.
**Your code so far**
function sym(args) {
console.log(arguments.length);
console.log(arguments[0], arguments[1]);
let symDif1 = [];
for (let i = 0; i < arguments[1].length; i++) {
if ((arguments[1][i] in arguments[0]) === false) {
symDif1.push(arguments[1][i]);
}
}
console.log(symDif1);
console.log(arguments.length);
console.log(arguments[0], arguments[1]);
let symDif2 = [];
for (let i = 0; i < arguments[0].length; i++) {
if ((arguments[0][i] in arguments[1]) === false) {
symDif2.push(arguments[0][i]);
}
}
console.log(symDif2);
return args;
}
sym([1, 2, 3], [5, 2, 1, 4]);
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36
Challenge: Algorithms - Find the Symmetric Difference
Link to the challenge: