Question presented to candidate: "Before these Set methods existed, you'd write manual loops (or filter/some combinations) to find the overlap between two Sets. What do union, intersection, difference, and symmetricDifference actually give you — and do any of them mutate the original Sets?"
What a strong answer should cover:
- 📌 Interview term:
Set.prototype.union(other)— returns a NEW Set containing every element from BOTH sets, real set-theory union — verified directly with two overlapping real Sets. - 📌 Interview term:
Set.prototype.intersection(other)— returns a new Set containing only elements present in BOTH sets. - 📌 Interview term:
Set.prototype.difference(other)— returns a new Set with elements in the FIRST set but NOT the second — verified directly to be genuinely asymmetric:a.difference(b)andb.difference(a)produce real, different results. - 📌 Interview term:
Set.prototype.symmetricDifference(other)— returns a new Set with elements in EITHER set but not both — verified directly. - 📌 Interview term: the real, direct answer to the prompt's mutation question — verified directly: none of these methods mutate the original Set at all — calling
.union()genuinely left the original Set's.sizecompletely unchanged, matching the identical non-mutating pattern this bank's own array-methods coverage establishes formap/filter/slice. - A precise answer names that these methods genuinely work on any "Set-like" object (anything with a real
.size,.has(), and.keys()), not strictly a realSetinstance — verified directly — plus the three real boolean-returning bonus methods that shipped alongside them:isSubsetOf,isSupersetOf,isDisjointFrom.
Clarifying questions expected:
- None — this is a definitional/technical question; directly answering the prompt's own mutation question (none of them mutate) is the strong signal.
Code / implementation expected: Yes — real results for all four operations on the same two overlapping Sets, plus the direct non-mutation proof, is the clearest demonstration.