mirror of
https://github.com/rjNemo/underscore
synced 2026-06-06 02:26:42 +00:00
* creating slice and pointer changes * removing extra file * switching to use 'sliceStable'
21 lines
371 B
Go
21 lines
371 B
Go
package underscore
|
|
|
|
import (
|
|
"sort"
|
|
|
|
"golang.org/x/exp/constraints"
|
|
)
|
|
|
|
// sort any slice ASENDING
|
|
func SortSliceASC[T constraints.Ordered](s []T) {
|
|
sort.SliceStable(s, func(i, j int) bool {
|
|
return s[i] < s[j]
|
|
})
|
|
}
|
|
|
|
// sort any slice DESCENDING
|
|
func SortSliceDESC[T constraints.Ordered](s []T) {
|
|
sort.SliceStable(s, func(i, j int) bool {
|
|
return s[i] > s[j]
|
|
})
|
|
}
|