mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-28 06:53:42 +08:00
* Fix Sandbox command transport and pinned native setup Build the Linux LLVM helper and runtime pack before running both test lanes, and align native cache contracts with the current target policy. Full managed Sandbox gate passed. * Replace quadratic array sorting with stable merge sort Cover sort snapshots, consistent-comparator results, stable ties, and comparator complexity with Node differential fixtures. Document differences from V8 TimSort.
47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
const receiver = [3, 1, 2];
|
|
const returned = receiver.sort((a, b) => a - b);
|
|
console.log(returned === receiver, receiver.join(","), returned.join(","));
|
|
|
|
const mutatedReceiver = [3, 1, 2];
|
|
let changedReceiver = false;
|
|
mutatedReceiver.sort((a, b) => {
|
|
if (!changedReceiver) {
|
|
changedReceiver = true;
|
|
mutatedReceiver[0] = 99;
|
|
}
|
|
return a - b;
|
|
});
|
|
console.log(mutatedReceiver.join(","));
|
|
|
|
const source = [3, 1, 2];
|
|
let changed = false;
|
|
const sorted = source.toSorted((a, b) => {
|
|
if (!changed) {
|
|
changed = true;
|
|
source[0] = 99;
|
|
source.push(4);
|
|
}
|
|
return a - b;
|
|
});
|
|
console.log(sorted.join(","));
|
|
console.log(source.join(","));
|
|
|
|
const stable = [
|
|
{ key: "b", order: 1 },
|
|
{ key: "a", order: 2 },
|
|
{ key: "b", order: 3 },
|
|
{ key: "a", order: 4 },
|
|
];
|
|
const byKey = stable.toSorted((a, b) => a.key.localeCompare(b.key));
|
|
console.log(byKey.map((entry) => entry.order).join(","));
|
|
console.log(stable.map((entry) => entry.order).join(","));
|
|
|
|
const throwing = [3, 1, 2];
|
|
try {
|
|
throwing.sort((a, b): number => {
|
|
throw new Error("stop");
|
|
});
|
|
} catch (error) {
|
|
console.log(error instanceof Error, throwing.join(","));
|
|
}
|