mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-02 08:35:07 +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.
19 lines
513 B
TypeScript
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);
|