mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-23 06:10:02 +08:00
Represent ordinary JavaScript arrays with hole, value, and explicit-undefined states; add sparse side storage and carry missing values through the frontend, native backends, runtime, and Node-facing consumers.
27 lines
636 B
TypeScript
27 lines
636 B
TypeScript
type MaybeNumber = number | undefined;
|
|
|
|
function describe(label: string, values: MaybeNumber[]): void {
|
|
const visits: string[] = [];
|
|
values.forEach((value, index) => {
|
|
visits.push(index + ":" + value);
|
|
});
|
|
console.log(label, values.length, visits.join("|"));
|
|
}
|
|
|
|
const values: MaybeNumber[] = [];
|
|
values[1] = 3;
|
|
values[3] = 1;
|
|
let firstComparison = true;
|
|
|
|
values.sort((left, right) => {
|
|
if (firstComparison) {
|
|
firstComparison = false;
|
|
values.push(99);
|
|
values[6] = 77;
|
|
}
|
|
return (left ?? 0) - (right ?? 0);
|
|
});
|
|
|
|
describe("sorted", values);
|
|
console.log("tail", values.length, values[4], values[5], values[6]);
|