Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Are values sorted?

  • StringsAreSorted
  • IntsAreSorted
  • Float64sAreSorted
package main

import (
	"fmt"
	"sort"
)

func main() {
	dwarfs := []string{"Doc", "Happy", "Grumpy"}
	fmt.Println(dwarfs)
	fmt.Println(sort.StringsAreSorted(dwarfs))

	sort.Strings(dwarfs)
	fmt.Println(dwarfs)
	fmt.Println(sort.StringsAreSorted(dwarfs))
	fmt.Println()

	greekNames := []string{"Alpha", "Beta"}
	fmt.Println(sort.StringsAreSorted(greekNames))
	fmt.Println()

	scores := []int{17, 3, 42, 28}
	fmt.Println(scores)
	fmt.Println(sort.IntsAreSorted(scores))
}
[Doc Happy Grumpy]
false
[Doc Grumpy Happy]
true

true

[17 3 42 28]
false