Help with code for a challenge that I don't understand

Hey, I have a bit of an issue with a code to get the variables back to what they were in the symmitric difference. how do I do that?

function sym(args){
return […args.reduce(reducer, new Set())]
}

function reducer(result, arr){
const compare = new Set(arr);
for(let val of compare){
if(result.has(val)){
result.delete(val);
}else{
result.add(val)
}
}
return result;
}


function sym(args) {
return args; reduce(reducer, new set())

}
function reducer(result, arr){
const compare = new set (arr);
for(let val of compare){
if(result.has(val)){
result.delete(val);
}else{
result.add(val)
}  
}
return result;
}

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/96.0.4664.110 Safari/537.36

Challenge: Find the Symmetric Difference

Could you explain in more details what do you mean? Some example also could help with understanding what issue you are having.

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