Initial commit
This commit is contained in:
commit
78f8d225ee
21173 changed files with 2907774 additions and 0 deletions
39
node_modules/d3-array/src/sort.js
generated
vendored
Normal file
39
node_modules/d3-array/src/sort.js
generated
vendored
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import ascending from "./ascending.js";
|
||||
import permute from "./permute.js";
|
||||
|
||||
export default function sort(values, ...F) {
|
||||
if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
|
||||
values = Array.from(values);
|
||||
let [f] = F;
|
||||
if ((f && f.length !== 2) || F.length > 1) {
|
||||
const index = Uint32Array.from(values, (d, i) => i);
|
||||
if (F.length > 1) {
|
||||
F = F.map(f => values.map(f));
|
||||
index.sort((i, j) => {
|
||||
for (const f of F) {
|
||||
const c = ascendingDefined(f[i], f[j]);
|
||||
if (c) return c;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
f = values.map(f);
|
||||
index.sort((i, j) => ascendingDefined(f[i], f[j]));
|
||||
}
|
||||
return permute(values, index);
|
||||
}
|
||||
return values.sort(compareDefined(f));
|
||||
}
|
||||
|
||||
export function compareDefined(compare = ascending) {
|
||||
if (compare === ascending) return ascendingDefined;
|
||||
if (typeof compare !== "function") throw new TypeError("compare is not a function");
|
||||
return (a, b) => {
|
||||
const x = compare(a, b);
|
||||
if (x || x === 0) return x;
|
||||
return (compare(b, b) === 0) - (compare(a, a) === 0);
|
||||
};
|
||||
}
|
||||
|
||||
export function ascendingDefined(a, b) {
|
||||
return (a == null || !(a >= a)) - (b == null || !(b >= b)) || (a < b ? -1 : a > b ? 1 : 0);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue