Slice Sorting
Add code to line A to sort s in ascending order
package main
import (
"fmt"
)
type S struct {
v int
}
func main() {
s := []S{{1}, {3}, {5}, {2}}
// A
fmt.Printf("%#v", s)
}
Answer
package main
import (
"fmt"
"sort"
)
type S struct {
v int
}
func main() {
s := []S{{1}, {3}, {5}, {2}}
sort.Slice(s, func(i, j int) bool { return s[i].v < s[j].v })
fmt.Printf("%#v", s)
}