JS Built-ins
← Set62 / 85
Setdifferenceintermediate

Set difference() β€” size

πŸ“– 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)

Verify the size of the difference Set.

Challenge: Verify size of A.difference(B).

πŸ’‘ Hints (1)
  • β€’ difference size = size of A minus the count of elements in both A and B