MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / Mean

Function Mean

math/mean.go:7–21  ·  view source on GitHub ↗
(values []T)

Source from the content-addressed store, hash-verified

5)
6
7func Mean[T constraints.Number](values []T) float64 {
8
9 if len(values) == 0 {
10 return 0
11 }
12
13 var summation float64 = 0
14
15 for _, singleValue := range values {
16 summation += float64(singleValue)
17 }
18
19 return summation / float64(len(values))
20
21}

Callers 1

TestMeanFunction · 0.92

Calls

no outgoing calls

Tested by 1

TestMeanFunction · 0.74