mirror of
https://github.com/samber/lo.git
synced 2026-04-22 23:47:11 +08:00
1.1 KiB
1.1 KiB
name, slug, sourceRef, category, subCategory, signatures, playUrl, variantHelpers, similarHelpers, position
| name | slug | sourceRef | category | subCategory | signatures | playUrl | variantHelpers | similarHelpers | position | |||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Mode | mode | it/math.go#L124 | it | math |
|
https://go.dev/play/p/c_cmMMA5EhH |
|
|
40 |
Returns the mode (most frequent value) of a collection. If multiple values have the same highest frequency, then multiple values are returned. If the collection is empty, then the zero value of T is returned.
Will iterate through the entire sequence and allocate a map large enough to hold all distinct elements. Long heterogeneous input sequences can cause excessive memory usage.
Examples:
seq := func(yield func(int) bool) {
_ = yield(1)
_ = yield(2)
_ = yield(2)
_ = yield(3)
_ = yield(3)
_ = yield(3)
}
mode := it.Mode(seq)
// mode == []int{3}
// Multiple modes
seq := func(yield func(string) bool) {
_ = yield("a")
_ = yield("b")
_ = yield("a")
_ = yield("b")
}
mode := it.Mode(seq)
// mode contains both "a" and "b" (order may vary)