underscore/max.go
2021-12-29 22:35:39 -04:00

14 lines
292 B
Go

package underscore
// Max returns the maximum value in the slice.
// This function can currently only compare numbers reliably.
// This function uses operator <.
func Max[T numbers](values []T) T {
max := values[0]
for _, v := range values {
if v > max {
max = v
}
}
return max
}