MCPcopy Index your code
hub / github.com/loiane/javascript-datastructures-algorithms / intersection

Method intersection

src/07-set/set.ts:123–132  ·  view source on GitHub ↗

* Returns a new set containing only elements present in both sets. * @param otherSet - The set to intersect with * @returns A new set with common elements * @complexity Time O(n) | Space O(n)

(otherSet: MySet)

Source from the content-addressed store, hash-verified

121 * @complexity Time O(n) | Space O(n)
122 */
123 intersection(otherSet: MySet): MySet {
124 const intersectionSet = new MySet();
125 const [smallerSet, largerSet] = this.size <= otherSet.size ? [this, otherSet] : [otherSet, this];
126 smallerSet.values().forEach(value => {
127 if (largerSet.has(value)) {
128 intersectionSet.add(value);
129 }
130 });
131 return intersectionSet;
132 }
133
134 /**
135 * Returns a new set with elements in this set but not in otherSet.

Callers 2

matchCandidateWithJobsFunction · 0.45
set.test.tsFile · 0.45

Calls 4

addMethod · 0.95
forEachMethod · 0.45
valuesMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected