JS Built-ins
← Set66 / 85
SetsymmetricDifferenceintermediate

Set symmetricDifference() β€” elements in either but not both

πŸ“– Usage Example
const a = new Set([1, 2, 3])
const b = new Set([2, 3, 4])
const sym = a.symmetricDifference(b)
console.log([...sym]) // β†’ [1, 4]

Use Set.symmetricDifference() to get elements in either set but not in both.

Set.prototype.symmetricDifference() (ES2025)

setA.symmetricDifference(setB) returns elements in either Set but not in both.

Challenge: Verify the symmetric difference.

πŸ’‘ Hints (1)
  • β€’ symmetricDifference = (A union B) - (A intersection B)