UNPKG

json-joy

Version:

Collection of libraries for building collaborative editing apps.

20 lines (19 loc) 616 B
export 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; };