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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user