typeover
curriculum

Curriculum Collections Arrays vs slices exercise 3 · mcq

Arrays vs slices

TypeScript needs .fill(0) to actually populate the array. Translate to idiomatic Go — the result is a slice of N real zeros, not a sparse array.

TypeScript reference
Pick the idiomatic Go translation

About this theme

Go has fixed-size arrays ([N]T) and dynamically-sized slices ([]T). You almost always want slices. A slice is a view over a backing array — three machine words: pointer, length, capacity. append grows it; make pre-sizes it. The mental model is closer to Rust's Vec than to TS's Array.