JS Built-ins
← Set53 / 85
Setunionintermediate

Set union() β€” non-overlapping

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

Use Set.union() to combine two sets into a new set containing all unique values.

Set.prototype.union() (ES2025)

Union of disjoint Sets contains all elements from both.

Challenge: Verify union of Sets with no common elements.

πŸ’‘ Hints (1)
  • β€’ For disjoint Sets, union size equals the sum of both sizes