Simple Sort Example
package main /* * Sort the command line parameters. That's kinda it. */ import ( "fmt" "os" "sort" "strings" ) func main() { // Single name makes it less awkward. data := os.Args[1:] // Use the library method to sort a slice. Notice that the comparison // function takes integer subscripts, not items to compare as some // other languages. Function returns boolean for first less than // second. This one compares strings in the slice case-insenitively. sort.Slice(data, func(i int, j int) bool { return strings.ToLower(data[i]) < strings.ToLower(data[j]) }) for _,s := range(data) { fmt.Print(s," ") } fmt.Println() }