json-joy
Version:
Collection of libraries for building collaborative editing apps.
18 lines (17 loc) • 405 B
JavaScript
const comparePathComponent = (a, b) => {
if (a === b)
return 0;
return a > b ? -1 : 1;
};
export const comparePath = (a, b) => {
const aLen = a.length;
const bLen = b.length;
if (aLen !== bLen)
return bLen - aLen;
for (let i = 0; i < aLen; i++) {
const c = comparePathComponent(a[i], b[i]);
if (c !== 0)
return c;
}
return 0;
};