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

Search in slice

package main

import (
	"fmt"
	"sort"
)

func main() {
	dwarfs := []string{"Doc", "Grumpy", "Happy", "Sleepy", "Bashful", "Sneezy", "Dopey"}
	fmt.Println(dwarfs)
	fmt.Printf("Length: %v\n", len(dwarfs))
	fmt.Printf("StringsAreSorted: %v\n", sort.StringsAreSorted(dwarfs))
	res := sort.SearchStrings(dwarfs, "Sleepy")
	fmt.Printf("Index of Sleepy %v\n", res)

	name := "Snow White"
	res = sort.SearchStrings(dwarfs, name)
	fmt.Printf("Index of '%v': %v\n", name, res)

}
[Doc Grumpy Happy Sleepy Bashful Sneezy Dopey]
Length: 7
StringsAreSorted: false
Index of Sleepy 3
Index of 'Snow White': 7