Skip to content
Snippets Groups Projects
Commit b74cdd2c authored by Alexander Rose's avatar Alexander Rose
Browse files

added missing return types for set utils

parent e79b2f02
No related branches found
No related tags found
No related merge requests found
...@@ -15,14 +15,14 @@ export function isSuperset<T>(setA: Set<T>, setB: Set<T>) { ...@@ -15,14 +15,14 @@ export function isSuperset<T>(setA: Set<T>, setB: Set<T>) {
} }
/** Create set containing elements of both set a and set b. */ /** Create set containing elements of both set a and set b. */
export function union<T>(setA: Set<T>, setB: Set<T>) { export function union<T>(setA: Set<T>, setB: Set<T>): Set<T> {
const union = new Set(setA); const union = new Set(setA);
for (const elem of Array.from(setB)) union.add(elem); for (const elem of Array.from(setB)) union.add(elem);
return union; return union;
} }
/** Create set containing elements of set a that are also in set b. */ /** Create set containing elements of set a that are also in set b. */
export function intersection<T>(setA: Set<T>, setB: Set<T>) { export function intersection<T>(setA: Set<T>, setB: Set<T>): Set<T> {
const intersection = new Set(); const intersection = new Set();
for (const elem of Array.from(setB)) { for (const elem of Array.from(setB)) {
if (setA.has(elem)) intersection.add(elem); if (setA.has(elem)) intersection.add(elem);
...@@ -31,7 +31,7 @@ export function intersection<T>(setA: Set<T>, setB: Set<T>) { ...@@ -31,7 +31,7 @@ export function intersection<T>(setA: Set<T>, setB: Set<T>) {
} }
/** Create set containing elements of set a that are not in set b. */ /** Create set containing elements of set a that are not in set b. */
export function difference<T>(setA: Set<T>, setB: Set<T>) { export function difference<T>(setA: Set<T>, setB: Set<T>): Set<T> {
const difference = new Set(setA); const difference = new Set(setA);
for (const elem of Array.from(setB)) difference.delete(elem); for (const elem of Array.from(setB)) difference.delete(elem);
return difference; return difference;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment