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

Method difference

src/07-set/set.ts:140–148  ·  view source on GitHub ↗

* Returns a new set with elements in this set but not in otherSet. * @param otherSet - The set to subtract * @returns A new set with the difference * @complexity Time O(n) | Space O(n)

(otherSet: MySet)

Source from the content-addressed store, hash-verified

138 * @complexity Time O(n) | Space O(n)
139 */
140 difference(otherSet: MySet): MySet {
141 const differenceSet = new MySet();
142 this.values().forEach(value => {
143 if (!otherSet.has(value)) {
144 differenceSet.add(value);
145 }
146 });
147 return differenceSet;
148 }
149
150 /**
151 * Returns true if every element of this set is also in otherSet.

Callers 2

set.test.tsFile · 0.45

Calls 4

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

Tested by

no test coverage detected