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.