sorting-by-functions
qianxi0410 opened this issue · 0 comments
qianxi0410 commented
This is not a issue!
I just want to say that we have an easier way to implement sorting-by-functions like this:
import (
"fmt"
"sort"
)
func main() {
fruits := []string{"peach", "banana", "kiwi"}
sort.Slice(fruits, func(i, j int) bool {
return len(fruits[i]) < len(fruits[j])
})
fmt.Println(fruits)
}