UNPKG

@thi.ng/compare

Version:

Comparators with support for types implementing the @thi.ng/api/ICompare interface

22 lines (21 loc) 373 B
const compare = (a, b) => { if (a === b) { return 0; } if (a == null) { return b == null ? 0 : -1; } if (b == null) { return a == null ? 0 : 1; } if (typeof a.compare === "function") { return a.compare(b); } if (typeof b.compare === "function") { return -b.compare(a); } return a < b ? -1 : a > b ? 1 : 0; }; export { compare };