Adding Mean and MeanBy (#414)

* feat: create Mean for ints and floats

* feat: create MeanBy for ints and floats

* chore: add example tests for mean Mean and MeanBy
This commit is contained in:
Usman Ahmed
2024-06-27 11:45:28 +00:00
committed by GitHub
parent 05a9bc93bd
commit 97074eeae7
3 changed files with 68 additions and 0 deletions

View File

@@ -66,3 +66,21 @@ func ExampleSumBy() {
fmt.Printf("%v", result)
// Output: 6
}
func ExampleMean() {
list := []int{1, 2, 3, 4, 5}
result := Mean(list)
fmt.Printf("%v", result)
}
func ExampleMeanBy() {
list := []string{"foo", "bar"}
result := MeanBy(list, func(item string) int {
return len(item)
})
fmt.Printf("%v", result)
}