Go sort a slice of runes?
Note: Go 1.8 will introduce helpers for sorting slices.
See issue 16721 and commit 22a2bdf by Brad Fitzpatrick
var strings = [...]string{"", "Hello", "foo", "bar", "foo", "f00", "%*&^*&^&", "***"}
func TestSlice(t *testing.T) {
data := strings
Slice(data[:], func(i, j int) bool {
return data[i] < data[j]
})
}
Use sort.Sort(data Interface)
and implement sort.Interface
, see the examples on package documentation.
You cannot use rune
which is int32
as int
. Check the comment of int
.
int is a signed integer type that is at least 32 bits in size. It is a distinct type, however, and not an alias for, say, int32.