underscore/min.go
Ruidy 3bfe1aca18
Code coverage (#15)
* 👷 adding test and push coverage

* ⬆️ use official Go 1.18 image

Co-authored-by: Ruidy <rnemausat@newstore.com>
2022-03-18 18:22:01 +01:00

16 lines
343 B
Go

package underscore
import "golang.org/x/exp/constraints"
// Min returns the minimum value in the slice.
// This function can currently only compare numbers reliably.
// This function uses operator <.
func Min[T constraints.Ordered](values []T) T {
min := values[0]
for _, v := range values {
if v < min {
min = v
}
}
return min
}