Min finds the lowest number in a set of data
(input Float64Data)
| 4 | |
| 5 | // Min finds the lowest number in a set of data |
| 6 | func Min(input Float64Data) (min float64, err error) { |
| 7 | |
| 8 | // Get the count of numbers in the slice |
| 9 | l := input.Len() |
| 10 | |
| 11 | // Return an error if there are no numbers |
| 12 | if l == 0 { |
| 13 | return math.NaN(), EmptyInputErr |
| 14 | } |
| 15 | |
| 16 | // Get the first value as the starting point |
| 17 | min = input.Get(0) |
| 18 | |
| 19 | // Iterate until done checking for a lower value |
| 20 | for i := 1; i < l; i++ { |
| 21 | if input.Get(i) < min { |
| 22 | min = input.Get(i) |
| 23 | } |
| 24 | } |
| 25 | return min, nil |
| 26 | } |