remove ginext/mongoext (no-dep lib)

This commit is contained in:
2022-10-27 16:07:42 +02:00
parent 568d7bd5e3
commit 47f123b86f
31 changed files with 6 additions and 123 deletions

41
mathext/statistics.go Normal file
View File

@@ -0,0 +1,41 @@
package mathext
func Sum(v []float64) float64 {
total := float64(0)
for _, v := range v {
total += v
}
return total
}
func Mean(v []float64) float64 {
return Sum(v) / float64(len(v))
}
func Median(v []float64) float64 {
if len(v)%2 == 1 {
return v[len(v)/2]
} else {
return (v[len(v)/2-1] + v[len(v)/2]) / float64(2)
}
}
func Min(v []float64) float64 {
r := v[0]
for _, val := range v {
if val < r {
r = val
}
}
return r
}
func Max(v []float64) float64 {
r := v[0]
for _, val := range v {
if val > r {
r = val
}
}
return r
}