Files
scriptc/tests/corpus/2704-array-sparse-to-sorted.ts
Chris Tate 94fd361b54 Implement sparse native arrays and missing-value parity (#297)
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.
2026-09-12 22:39:07 -05:00

19 lines
513 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 source: MaybeNumber[] = [];
source[2] = 20;
source[5] = undefined;
const copy = source.toSorted((left, right) => (left ?? 0) - (right ?? 0));
describe("source", source);
describe("copy", copy);
console.log("same", source === copy);