how about adding argMax which return the index of max element from a slice ?
JellyZhang opened this issue · comments
Jelly commented
Like the max function, argMax would return the index of max element from a slice. For example:
func argMax(nums []int64) int {
if len(nums) == 0 {
panic("error")
}
var maxNum int64
var maxIndex int
for i, num := range nums {
if i == 0 {
maxNum = num
maxIndex = 0
continue
}
if num > maxNum {
maxNum = num
maxIndex = i
}
}
return maxIndex
}
If there are duplicate occurrences of max element, only return the first one.