mirror of
https://github.com/samber/lo.git
synced 2025-10-05 07:56:51 +08:00
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:
@@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user