Lesson 19 of 38 · Slices & Maps
Quiz: Go Slices and Maps
Slices and maps are the two collections you'll use in almost every Go program. In this chapter you learned that an array's size is part of its type while a slice is a flexible view over an array, that append returns the updated slice, how len and cap drive reallocation, and why sub-slices can overwrite each other. On the map side you used the comma-ok idiom to tell missing keys from zero values, sorted keys for a predictable order, and learned why a nil map can be read but never written.
Answer these six questions, then go and face the Hoarding Dragon.
What this quiz covers
The questions check what you learned in the Slices & Maps chapter of Learn Go. Not sure about a topic? Review its lesson first:
- Go Arrays vs Slices: Slicing and range
Learn the difference between Go arrays and slices: fixed-size arrays, slice literals, slicing with s[low:high], shared elements and range loops.
- Go Slices: append, make, len and cap
Grow Go slices with append, preallocate them with make, understand len vs cap, copy safely, avoid the aliasing trap and use the slices package.
- Sorting Slices and 2D Slices in Go
Sort Go slices with sort.Ints, sort.Slice and slices.SortFunc, keep sorts stable, and build 2D slices and grids with make and nested range loops.
- Go Maps: Create, Read, Update, Delete and comma-ok
Learn Go maps: literals and make, reading, updating and deleting keys, the comma-ok idiom, nil maps, sets and the counts[key]++ counting pattern.
Keep learning
Need a quick reminder? The Go cheat sheet has every topic of Learn Go on one page.
Lesson last updated on .