Back to Lo

It Minindex

docs/data/it-minindex.md

1.53.0456 B
Original Source

Searches the minimum 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:

go
// Find the minimum value and its index
numbers := it.Slice([]int{5, 2, 8, 1, 9})
value, index := it.MinIndex(numbers)
// value: 1, index: 3

// With empty collection
empty := it.Slice([]int{})
value, index := it.MinIndex(empty)
// value: 0, index: -1