JS Built-ins
← Set64 / 85
Setdifferenceintermediate

Set difference() β€” B empty keeps A

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

Use Set.difference() to get elements in the first set that are not in the second.

Set.prototype.difference() (ES2025)

When B is empty, difference equals A.

Challenge: Verify that A.difference(empty) equals A.

πŸ’‘ Hints (1)
  • β€’ A - βˆ… = A; removing nothing leaves everything