The following exercises will help solidify your knowledge of slices.
-
Starting from a
nil[]int,appendone value at a time, printing length and capacity after each call until capacity reaches 16. Predict the sequence before you run it. -
Create s:= []int{1, 2, 3, 4, 5}. Take a subslice of length 3 starting at index 1, using a three-part slice expression to set its capacity to 3. Append 100 to the subslice. Print both slices and explain why the parent is unchanged.
-
Use
slices.EqualFunctogether withstrings.EqualFoldto compare two []string values for case-insensitive equality. Cover the cases of equal, unequal, and different lengths.
Progress is saved on this device.