mute-structs
Version:
NodeJS module providing an implementation of the LogootSplit CRDT algorithm
36 lines • 1.03 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
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];
}
exports.findPredecessor = findPredecessor;
/**
* 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
*/
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 */;
});
}
exports.isSorted = isSorted;
//# sourceMappingURL=helpers.js.map