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

Method union

src/07-set/set.ts:110–115  ·  view source on GitHub ↗

* Returns a new set containing all elements from both sets. * @param otherSet - The set to union with * @returns A new set with all elements * @complexity Time O(n+m) | Space O(n+m)

(otherSet: MySet)

Source from the content-addressed store, hash-verified

108 * @complexity Time O(n+m) | Space O(n+m)
109 */
110 union(otherSet: MySet): MySet {
111 const unionSet = new MySet();
112 this.values().forEach(value => unionSet.add(value));
113 otherSet.values().forEach(value => unionSet.add(value));
114 return unionSet;
115 }
116
117 /**
118 * Returns a new set containing only elements present in both sets.

Callers 2

set.test.tsFile · 0.45

Calls 3

valuesMethod · 0.95
addMethod · 0.95
forEachMethod · 0.45

Tested by

no test coverage detected