1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-09 23:22:28 +08:00

feat: add Sum

This commit is contained in:
dudaodong
2023-06-08 16:18:25 +08:00
parent 83832daeb1
commit c11d63c2e2
3 changed files with 31 additions and 0 deletions

View File

@@ -172,6 +172,18 @@ func MinBy[T any](slice []T, comparator func(T, T) bool) T {
return min
}
// Sum return sum of passed numbers.
// Play: todo
func Sum[T constraints.Integer | constraints.Float](numbers ...T) T {
var sum T
for _, v := range numbers {
sum += v
}
return sum
}
// Average return average value of numbers.
// Play: https://go.dev/play/p/Vv7LBwER-pz
func Average[T constraints.Integer | constraints.Float](numbers ...T) T {