MCPcopy Create free account
hub / github.com/d3/d3-array / compareDefined

Function compareDefined

src/sort.js:27–35  ·  view source on GitHub ↗
(compare = ascending)

Source from the content-addressed store, hash-verified

25}
26
27export function compareDefined(compare = ascending) {
28 if (compare === ascending) return ascendingDefined;
29 if (typeof compare !== "function") throw new TypeError("compare is not a function");
30 return (a, b) => {
31 const x = compare(a, b);
32 if (x || x === 0) return x;
33 return (compare(b, b) === 0) - (compare(a, a) === 0);
34 };
35}
36
37export function ascendingDefined(a, b) {
38 return (a == null || !(a >= a)) - (b == null || !(b >= b)) || (a < b ? -1 : a > b ? 1 : 0);

Callers 3

quickselectFunction · 0.90
rankFunction · 0.90
sortFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…