Slice is a growable sequence of values of the same type.

Other languages call them arrays or vectors.

Memory used by slice is provided by a fixed size array. A slice is a view into that array.

Slice has length and capacity.

Capacity represents how many total elements a slice can have. That’s the size of underlying array.

Length is the current number of elements in the slice.

The difference between capacity and length is how many elements we can append to a slice before we have to re-allocate underlying array.

Zero value of a slice is nil.

Basic of slices

https://codeeval.dev/gist/3b1a53c71e2ad9a43ad51c385fcd5c14

Create a slice

Length and capacity

Append to slice

Filter a slice

Remove elements from slice

Duplicate a slice

Zero value of slice

Slice tricks

Optimize by pre-allocating slice