JS: Set.prototype.symmetricDifference
(new in JS: ECMAScript 2024)
setA.symmetricDifference(setB)
-
- Return a set that is union minus intersection.
- setB can be a Map.
const xx = new Set([4, 5, 6]) const yy = new Set([6, 7, 8]) console.log(xx.symmetricDifference(yy)) // Set(4) { 4, 5, 7, 8 }
// symmetric difference of 2 map's keys const mapA = new Map([[4, 0], [5, 0], [6, 0]]) const mapB = new Map([[6, 0], [7, 0], [8, 0]]) console.log((new Set(mapA.keys())).symmetricDifference(mapB)) // Set(4) { 4, 5, 7, 8 }