diff --git a/src/comparisons/pairwise-disjoint.function.ts b/src/comparisons/pairwise-disjoint.function.ts index a50d475..68e8099 100644 --- a/src/comparisons/pairwise-disjoint.function.ts +++ b/src/comparisons/pairwise-disjoint.function.ts @@ -15,7 +15,19 @@ export function pairwiseDisjoint>(...sets: S[]): boo return true; } - const allElements = new Set(sets.shift()); + const primarySet = sets.shift()!; + const secondarySet = sets.shift()!; + for (const element of secondarySet) { + if (primarySet.has(element)) { + return false; + } + } + + if (sets.length === 0) { + return true; + } + + const allElements = new Set([ ...primarySet, ...secondarySet ]); for (const set of sets) { for (const element of set) { if (allElements.has(element)) {