mirror of
https://github.com/samber/lo.git
synced 2026-04-22 23:47:11 +08:00
fa095e4b4f
* fix(doc): fix go playground demo URL * fix(doc): add more go playground demo URL
35 lines
690 B
Markdown
35 lines
690 B
Markdown
---
|
|
name: MaxIndex
|
|
slug: maxindex
|
|
sourceRef: find.go#L432
|
|
category: core
|
|
subCategory: find
|
|
playUrl: https://go.dev/play/p/RFkB4Mzb1qt
|
|
variantHelpers:
|
|
- core#find#maxindex
|
|
similarHelpers:
|
|
- core#find#max
|
|
- core#find#maxby
|
|
- core#find#maxindexby
|
|
- core#find#min
|
|
- core#find#minby
|
|
- core#find#minindex
|
|
- core#find#minindexby
|
|
- core#math#sum
|
|
- core#math#mean
|
|
- core#math#product
|
|
- core#math#mode
|
|
position: 210
|
|
signatures:
|
|
- "func MaxIndex[T constraints.Ordered](collection []T) (T, int)"
|
|
---
|
|
|
|
Returns the maximum value and its index. Returns (zero value, -1) when the collection is empty.
|
|
|
|
```go
|
|
value, idx := lo.MaxIndex([]int{2, 5, 3})
|
|
// value == 5, idx == 1
|
|
```
|
|
|
|
|