typeover
curriculum

Curriculum Memory ArrayList exercise 1 · mcq

ArrayList

TypeScript reaches for const nums: number[] = [] to start an empty growable list. Zig's std.ArrayList(T) is the same idea — but in Zig 0.16 it's an unmanaged container, so you start with the .empty literal and pass the allocator on each mutating call. Pick the right initialization.

TypeScript reference
Pick the idiomatic Go translation

About this theme

ArrayList(T) is Zig's growable slice — your TypeScript Array equivalent. In Zig 0.16 it's an unmanaged container by API convention: you initialize with the .empty literal, pass the allocator on every mutating call (append, insert, etc.), and call .deinit(allocator) to release. items is a []T view into the live elements; the capacity is hidden. The benefit of unmanaged: no per-list allocator pointer overhead, and the list type is a plain struct you can store in a hash map's value.