UNPKG

mute-structs

Version:

NodeJS module providing an implementation of the LogootSplit CRDT algorithm

32 lines 900 B
export function findPredecessor(list, element, compareFn) { var l = 0; var r = list.length; while (l < r) { var m = Math.floor((l + r) / 2); var 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(function (value, index) { if (index === 0) { return true; } var other = array[index - 1]; return compareFn(other, value) === -1 /* Less */; }); } //# sourceMappingURL=helpers.js.map