Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions arrays-and-slices.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,9 @@ func SumAll(numbersToSum ...[]int) []int {
In this implementation, we are worrying less about capacity. We start with an
empty slice `sums` and append to it the result of `Sum` as we work through the varargs.

However, If we were to pre-allocate the capacity of the slice using `make([]int, 0, lengthOfNumbers)`.
This would avoid unnecessary memory allocations due to the slice size already being known.

Our next requirement is to change `SumAll` to `SumAllTails`, where it will
calculate the totals of the "tails" of each slice. The tail of a collection is
all items in the collection except the first one \(the "head"\).
Expand Down