Skip to content
Snippets Groups Projects
Commit 8d13c514 authored by David Sehnal's avatar David Sehnal
Browse files

mol-data: SortedArray fix

parent f57aafba
No related branches found
No related tags found
No related merge requests found
...@@ -171,13 +171,17 @@ export function isSubset(a: Nums, b: Nums) { ...@@ -171,13 +171,17 @@ export function isSubset(a: Nums, b: Nums) {
return equal === lenB; return equal === lenB;
} }
export function union(a: Nums, b: Nums) { export function union(a: Nums, b: Nums): Nums {
if (a === b) return a; if (a === b) return a;
const lenA = a.length, lenB = b.length;
if (lenA === 0) return b;
if (lenB === 0) return a;
if (a[0] > b[0]) return union(b, a);
const { startI, startJ, endI, endJ } = getSuitableIntersectionRange(a, b); const { startI, startJ, endI, endJ } = getSuitableIntersectionRange(a, b);
const commonCount = getCommonCount(a, b, startI, startJ, endI, endJ); const commonCount = getCommonCount(a, b, startI, startJ, endI, endJ);
const lenA = a.length, lenB = b.length;
// A === B || B is subset of A ==> A // A === B || B is subset of A ==> A
if ((commonCount === lenA && commonCount === lenB) || commonCount === lenB) return a; if ((commonCount === lenA && commonCount === lenB) || commonCount === lenB) return a;
// A is subset of B ===> B // A is subset of B ===> B
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment