MCPcopy
hub / github.com/montanaflynn/stats / Max

Function Max

max.go:8–26  ·  view source on GitHub ↗

Max finds the highest number in a slice

(input Float64Data)

Source from the content-addressed store, hash-verified

6
7// Max finds the highest number in a slice
8func Max(input Float64Data) (max float64, err error) {
9
10 // Return an error if there are no numbers
11 if input.Len() == 0 {
12 return math.NaN(), EmptyInputErr
13 }
14
15 // Get the first value as the starting point
16 max = input.Get(0)
17
18 // Loop and replace higher values
19 for i := 1; i < input.Len(); i++ {
20 if input.Get(i) > max {
21 max = input.Get(i)
22 }
23 }
24
25 return max, nil
26}

Callers 10

ExampleMaxFunction · 0.92
TestMaxFunction · 0.92
TestDescribeValuesFunction · 0.92
BenchmarkRegularAPIFunction · 0.92
mainFunction · 0.92
SoftMaxFunction · 0.85
DescribePercentileFuncFunction · 0.85
MaxMethod · 0.85

Calls 2

LenMethod · 0.80
GetMethod · 0.80

Tested by 6

ExampleMaxFunction · 0.74
TestMaxFunction · 0.74
TestDescribeValuesFunction · 0.74
BenchmarkRegularAPIFunction · 0.74