# Algorithms - Find the Symmetric Difference

Tell us what’s happening:
Can someone explain what is wrong with my solution

``````function sym(args) {
var currentElement =[]
for(var i =0; i< args.length; i+=2){
if(i ==0){
currentElement = args[i]
}else{
currentElement = checkSym(currentElement, args[i]);
}
if(i !== args.length-1){
currentElement = checkSym(currentElement, args[i+1]);
}

}
return currentElement;
}
function checkSym(a1, a2){
const a = a1.filter(x=> !a2.includes(x));
const b = a2.filter(x=> !a1.includes(x));
const result = a.concat(b);
return result;
}

sym([[1, 2, 3], [5, 2, 1, 4]]);
``````

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 Edg/115.0.1901.188`

Challenge: Algorithms - Find the Symmetric Difference

Minor formatting fixes:

``````function sym(args) {
let currentElement = [];
for (let i = 0; i < args.length; i += 2) {
if (i === 0) {
currentElement = args[i];
} else {
currentElement = checkSym(currentElement, args[i]);
}
if (i !== args.length - 1) {
currentElement = checkSym(currentElement, args[i + 1]);
}

}
return currentElement;
}

function checkSym(a1, a2) {
const a = a1.filter(x => !a2.includes(x));
const b = a2.filter(x => !a1.includes(x));
const result = a.concat(b);
return result;
}

sym([[1, 2, 3], [5, 2, 1, 4]]);
``````

It looks like you changed the meaning of the function signature of `sym` - look at the sample function calls.

Also, you aren’t handling duplication inside of a single array.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.