Created
February 21, 2017 17:27
-
-
Save geraldstanje/926e04e27c467132c35fe60e1e1dd6a8 to your computer and use it in GitHub Desktop.
sorting in go 1.8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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