JS Built-ins
← Set57 / 85
Setintersectionintermediate

Set intersection() β€” size

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

Use Set.intersection() to get the values present in both sets.

Set.prototype.intersection() (ES2025)

The size of the intersection is the count of common elements.

Challenge: Verify the size of the intersection.

πŸ’‘ Hints (1)
  • β€’ intersection size can range from 0 to min(size_A, size_B)