Sort slice
-
sort
-
sort.Strings
-
sort.Ints
package main
import (
"fmt"
"sort"
)
func main() {
dwarfs := []string{"Doc", "Grumpy", "Happy", "Sleepy", "Bashful", "Sneezy", "Dopey"}
fmt.Println(dwarfs)
sort.Strings(dwarfs)
fmt.Println(dwarfs)
scores := []int{17, 3, 42, 28}
fmt.Println(scores)
sort.Ints(scores)
fmt.Println(scores)
}
[Doc Grumpy Happy Sleepy Bashful Sneezy Dopey]
[Bashful Doc Dopey Grumpy Happy Sleepy Sneezy]
[17 3 42 28]
[3 17 28 42]