(values, ...F)
| 2 | import permute from "./permute.js"; |
| 3 | |
| 4 | export 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 | |
| 27 | export function compareDefined(compare = ascending) { |
| 28 | if (compare === ascending) return ascendingDefined; |
no test coverage detected
searching dependent graphs…