Files
obitools4/pkg/obiutils/minmax.go
Eric Coissac dd9307a4cd Swich to the system min and max functions and remove the version from obiutils
Former-commit-id: 8c4558921b0d0c266b070f16e83813de6e6d4a0f
2024-05-30 08:27:24 +02:00

32 lines
397 B
Go

package obiutils
import (
"golang.org/x/exp/constraints"
)
func MinMax[T constraints.Ordered](x, y T) (T, T) {
if x < y {
return x, y
}
return y, x
}
func MinMaxSlice[T constraints.Ordered](vec []T) (min, max T) {
if len(vec) == 0 {
panic("empty slice")
}
min = vec[0]
max = vec[0]
for _, v := range vec {
if v > max {
max = v
}
if v < min {
min = v
}
}
return
}