1
0
Fork 0
mirror of https://github.com/Luzifer/webcheck.git synced 2024-11-08 22:50:01 +00:00
webcheck/vendor/github.com/montanaflynn/stats/max.go
Knut Ahlers 2fbabd6bd4
Vendor dependencies
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2018-07-23 14:54:12 +02:00

24 lines
445 B
Go

package stats
import "math"
// Max finds the highest number in a slice
func Max(input Float64Data) (max float64, err error) {
// Return an error if there are no numbers
if input.Len() == 0 {
return math.NaN(), EmptyInput
}
// Get the first value as the starting point
max = input.Get(0)
// Loop and replace higher values
for i := 1; i < input.Len(); i++ {
if input.Get(i) > max {
max = input.Get(i)
}
}
return max, nil
}