Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
samber authored Jun 27, 2024
1 parent b23221e commit 96c7f9c
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ Supported math helpers:
- [Clamp](#clamp)
- [Sum](#sum)
- [SumBy](#sumby)
- [Mean](#mean)
- [MeanBy](#meanby)

Supported helpers for strings:

Expand Down Expand Up @@ -1235,6 +1237,42 @@ sum := lo.SumBy(strings, func(item string) int {

[[play](https://go.dev/play/p/Dz_a_7jN_ca)]

### Mean

Calculates the mean of a collection of numbers.

If collection is empty 0 is returned.

```go
mean := lo.Mean([]int{2, 3, 4, 5})
// 3

mean := lo.Mean([]float64{2, 3, 4, 5})
// 3.5

mean := lo.Mean([]float64{})
// 0
```

### MeanBy

Calculates the mean of a collection of numbers using the given return value from the iteration function.

If collection is empty 0 is returned.

```go
list := []string{"aa", "bbb", "cccc", "ddddd"}
mapper := func(item string) float64 {
return float64(len(item))
}

mean := lo.MeanBy(list, mapper)
// 3.5

mean := lo.MeanBy([]float64{}, mapper)
// 0
```

### RandomString

Returns a random string of the specified length and made of the specified charset.
Expand Down

0 comments on commit 96c7f9c

Please sign in to comment.