This commit is contained in:
Mark McGranaghan
2012-09-23 11:47:31 -07:00
parent e02b47ea22
commit accda24c6d
13 changed files with 89 additions and 63 deletions

View File

@@ -1,3 +1,5 @@
// ## Sort by Function
package main
import ("fmt" ; "sort")
@@ -36,13 +38,10 @@ func main() {
{"Bob", 12},
}
fmt.Println("Original:", kids)
fmt.Println()
sort.Sort(ByName(kids))
fmt.Println("ByName: ", kids)
fmt.Println()
sort.Sort(ByAge(kids))
fmt.Println("ByAge: ", kids)
fmt.Println()
}

View File

@@ -0,0 +1,4 @@
$ go run sort-by-function.go
Original: [{Jack 10} {Jill 9} {Bob 12}]
ByName: [{Bob 12} {Jack 10} {Jill 9}]
ByAge: [{Jill 9} {Jack 10} {Bob 12}]