Need help with "Find Symmetric Difference"

Need help with this solution, this is giving me the correct solution, however, this is failing the test on FCC, can someone help?

Unable to come to a solution (don’t want to look at hints too early)


function sym(...args) {
const mySet = new Set();
for(let arr of args){
  for(let elem of arr){
    if(mySet.has(elem)){
      mySet.delete(elem)
    }else{
      mySet.add(elem)
    }
  } 
}
let retArr = Array.from(mySet);
return retArr.sort();
}

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

Challenge: Find the Symmetric Difference

Link to the challenge:


Hello there.

Do you have a question?

If so, please edit your post to include it in the Tell us what’s happening section.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more information you give us, the more likely we are to be able to help.


It doesn’t look like your code produces the correct results:

function sym(...args) {
  const mySet = new Set();
  for (let arr of args) {
    for (let elem of arr) {
      if (mySet.has(elem)) {
        mySet.delete(elem);
      } else {
        mySet.add(elem);
      }
    }
  }
  const retArr = Array.from(mySet);
  return retArr.sort();
}

/// sym([1, 2, 3, 3], [5, 2, 1, 4]) should return [3, 4, 5].
console.log(sym([1, 2, 3, 3], [5, 2, 1, 4]));

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