mirror of
https://github.com/samber/lo.git
synced 2026-04-22 23:47:11 +08:00
964 B
964 B
name, slug, sourceRef, category, subCategory, signatures, playUrl, variantHelpers, similarHelpers, position
| name | slug | sourceRef | category | subCategory | signatures | playUrl | variantHelpers | similarHelpers | position | |||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| MaxIndex | maxindex | it/find.go#L299 | it | find |
|
https://go.dev/play/p/0HbUY4-zg |
|
|
480 |
Searches the maximum value of a collection and returns both the value and its index.
Returns (zero value, -1) when the collection is empty. Will iterate through the entire sequence.
Examples:
// Find the maximum value and its index
numbers := it.Slice([]int{5, 2, 8, 1, 9})
value, index := it.MaxIndex(numbers)
// value: 9, index: 4
// With empty collection
empty := it.Slice([]int{})
value, index := it.MaxIndex(empty)
// value: 0, index: -1
// Find the maximum string alphabetically and its index
words := it.Slice([]string{"apple", "zebra", "banana", "xylophone"})
value, index := it.MaxIndex(words)
// value: "zebra", index: 1