json-joy
Version:
Collection of libraries for building collaborative editing apps.
24 lines (23 loc) • 754 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.commonLength = void 0;
const commonLength = (a, b) => {
const aLength = a.length;
const bLength = b.length;
let i = 0;
while (i < aLength && i < bLength) {
const aStep = a[i];
const bStep = b[i];
const aTag = Array.isArray(aStep) ? aStep[0] : aStep;
const bTag = Array.isArray(bStep) ? bStep[0] : bStep;
if (aTag !== bTag)
break;
const aDiscriminant = Array.isArray(aStep) ? aStep[1] : 0;
const bDiscriminant = Array.isArray(bStep) ? bStep[0] : 0;
if (aDiscriminant !== bDiscriminant)
break;
i++;
}
return i;
};
exports.commonLength = commonLength;
;