linked-list-lib
Version:
This package contain some possibilities of implementations of linked lists
77 lines (76 loc) • 2.3 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Comparator = void 0;
const _ = require("lodash");
class Comparator {
equal(a, b) {
if (this.isObject(a) || this.isObject(b)) {
return _.isEqual(a, b);
}
return a === b;
}
lessThanOrEqual(a, b, aKey) {
if (this.isObject(a) || this.isObject(b)) {
return this.matchesLessThanOrEqual(aKey, a)(b);
}
return a <= b;
}
strictlyLessThan(a, b, aKey) {
if (this.isObject(a) || this.isObject(b)) {
return this.matchesStrictlyLessThan(aKey, a)(b);
}
return a < b;
}
moreThanOrEqual(a, b, aKey) {
if (this.isObject(a) || this.isObject(b)) {
return this.matchesMoreThanOrEqual(aKey, a)(b);
}
return a >= b;
}
strictlyMoreThan(a, b, aKey) {
if (this.isObject(a) || this.isObject(b)) {
return this.matchesStrictlyMoreThan(aKey, a)(b);
}
return a > b;
}
isObject(value) {
return value !== null && typeof value === 'object';
}
matchesLessThanOrEqual(key, srcValue) {
return (object) => {
if (object == null) {
return false;
}
return object[key] <= srcValue &&
(srcValue !== undefined || (key in Object(object)));
};
}
matchesMoreThanOrEqual(key, srcValue) {
return (object) => {
if (object == null) {
return false;
}
return object[key] >= srcValue &&
(srcValue !== undefined || (key in Object(object)));
};
}
matchesStrictlyMoreThan(key, srcValue) {
return (object) => {
if (object == null) {
return false;
}
return object[key] > srcValue &&
(srcValue !== undefined || (key in Object(object)));
};
}
matchesStrictlyLessThan(key, srcValue) {
return (object) => {
if (object == null) {
return false;
}
return object[key] < srcValue &&
(srcValue !== undefined || (key in Object(object)));
};
}
}
exports.Comparator = Comparator;