Q:

Write a JavaScript program to get the symmetric difference between two given arrays

0

Write a JavaScript program to get the symmetric difference between two given arrays.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

const symmetricDifference = (a, b) => {
  const sA = new Set(a),
    sB = new Set(b);
  return [...a.filter(x => !sB.has(x)), ...b.filter(x => !sA.has(x))];
};

console.log(symmetricDifference([1, 2, 3], [1, 2, 4]));

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now