underscore/slices.go
2024-10-15 23:33:46 -05:00

21 lines
359 B
Go

package underscore
import (
"sort"
"golang.org/x/exp/constraints"
)
// sort any slice ASENDING
func SortSliceASC[T constraints.Ordered](s []T) {
sort.Slice(s, func(i, j int) bool {
return s[i] < s[j]
})
}
// sort any slice DESCENDING
func SortSliceDESC[T constraints.Ordered](s []T) {
sort.Slice(s, func(i, j int) bool {
return s[i] > s[j]
})
}