Sort List
Examples in
Go
package main
import (
"fmt"
"sort"
)
func main() {
fruit := []string{"Apple", "Banana", "Mango", "Orange"}
// Custom sort based on the second letter of the word.
sort.Slice(fruit, func(i, j int) bool {
return fruit[i][1] < fruit[j][1]
})
fmt.Println(fruit)
}
Last Run
:
[Banana Mango Apple Orange]