Skip to content

Instantly share code, notes, and snippets.

@geraldstanje
Created February 21, 2017 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geraldstanje/926e04e27c467132c35fe60e1e1dd6a8 to your computer and use it in GitHub Desktop.
Save geraldstanje/926e04e27c467132c35fe60e1e1dd6a8 to your computer and use it in GitHub Desktop.
sorting in go 1.8
package main
import (
"fmt"
"sort"
)
func tokensByAscending(t []int) func(i, j int) bool {
return func(i, j int) bool {
return t[i] < t[j]
}
}
func main() {
tokens := []int{
1,
2,
44123,
8,
3,
2,
99,
6,
}
sort.Slice(tokens, tokensByAscending(tokens))
fmt.Println(tokens)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment