mirror of
https://github.com/rjNemo/underscore
synced 2026-06-06 02:26:42 +00:00
* 👷 adding test and push coverage * ⬆️ use official Go 1.18 image Co-authored-by: Ruidy <rnemausat@newstore.com>
16 lines
343 B
Go
16 lines
343 B
Go
package underscore
|
|
|
|
import "golang.org/x/exp/constraints"
|
|
|
|
// Max returns the maximum value in the slice.
|
|
// This function can currently only compare numbers reliably.
|
|
// This function uses operator <.
|
|
func Max[T constraints.Ordered](values []T) T {
|
|
max := values[0]
|
|
for _, v := range values {
|
|
if v > max {
|
|
max = v
|
|
}
|
|
}
|
|
return max
|
|
}
|