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

Function sort

src/sort.js:4–25  ·  view source on GitHub ↗
(values, ...F)

Source from the content-addressed store, hash-verified

2import permute from "./permute.js";
3
4export default function sort(values, ...F) {
5 if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
6 values = Array.from(values);
7 let [f] = F;
8 if ((f && f.length !== 2) || F.length > 1) {
9 const index = Uint32Array.from(values, (d, i) => i);
10 if (F.length > 1) {
11 F = F.map(f => values.map(f));
12 index.sort((i, j) => {
13 for (const f of F) {
14 const c = ascendingDefined(f[i], f[j]);
15 if (c) return c;
16 }
17 });
18 } else {
19 f = values.map(f);
20 index.sort((i, j) => ascendingDefined(f[i], f[j]));
21 }
22 return permute(values, index);
23 }
24 return values.sort(compareDefined(f));
25}
26
27export function compareDefined(compare = ascending) {
28 if (compare === ascending) return ascendingDefined;

Callers 2

sort-test.jsFile · 0.90
groupSortFunction · 0.85

Calls 3

ascendingDefinedFunction · 0.85
permuteFunction · 0.85
compareDefinedFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…