lgrthms
Version:
Algorithms and data structures for your JavaScript and TypeScript projects 🧑💻
33 lines (32 loc) • 824 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Comparator = void 0;
class Comparator {
compare(a, b) {
if (a === b) {
return 0;
}
return a < b ? -1 : 1; // eslint-disable-line no-magic-numbers
}
constructor(compareFn) {
if (compareFn) {
this.compare = compareFn;
}
}
isEqual(a, b) {
return this.compare(a, b) === 0;
}
isLessThan(a, b) {
return this.compare(a, b) < 0;
}
isGreaterThan(a, b) {
return this.compare(a, b) > 0;
}
isLessThanOrEqual(a, b) {
return this.isLessThan(a, b) || this.isEqual(a, b);
}
isGreaterThanOrEqual(a, b) {
return this.isGreaterThan(a, b) || this.isEqual(a, b);
}
}
exports.Comparator = Comparator;