UNPKG

mute-structs

Version:

NodeJS module providing an implementation of the LogootSplit CRDT algorithm

32 lines 900 B
export function findPredecessor(list, element, compareFn) { let l = 0; let r = list.length; while (l < r) { const m = Math.floor((l + r) / 2); const other = list[m]; if (compareFn(other, element) === -1 /* Less */) { l = m + 1; } else { r = m; } } return list[l - 1]; } /** * Check if an array is sorted * * @param {T[]} array The array to browse * @param {(a: T, b: T) => Ordering} compareFn The comparison function used to determine the order between two elements * @return {boolean} Is the array sorted */ export function isSorted(array, compareFn) { return array.every((value, index) => { if (index === 0) { return true; } const other = array[index - 1]; return compareFn(other, value) === -1 /* Less */; }); } //# sourceMappingURL=helpers.js.map