The slices Package
slices has Sort, Contains, Index, Reverse, Max and more for any slice.
Example
package main
import (
"fmt"
"slices"
)
func main() {
a := []int{3, 1, 2}
slices.Sort(a)
fmt.Println(a, slices.Contains(a, 2), slices.Index(a, 3), slices.Max(a))
slices.Reverse(a)
fmt.Println(a)
}Result
[1 2 3] true 2 3 [3 2 1]
Exercise
Test presence.
slices.(a, 2)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.