This repository has been archived on 2024-04-10. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
elektron/vendor/github.com/montanaflynn/stats/max.go
Pradyumna Kaushik bac60e872a Unit testing for def/ module.
Added unit tests to test code in def/ module.
2019-10-12 06:48:45 +00:00

26 lines
453 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(), EmptyInputErr
}
// 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
}