Skip to content

Instantly share code, notes, and snippets.

@rsbohn
Created May 24, 2024 20:02
Show Gist options
  • Save rsbohn/96261438b2b32e0f049153eacc99abde to your computer and use it in GitHub Desktop.
Save rsbohn/96261438b2b32e0f049153eacc99abde to your computer and use it in GitHub Desktop.
Collection>>argmax
!Collection methodsFor: 'statistics' stamp: 'rsbohn 5/24/2024 13:45:07'!
argmax
"Returns the index of the maximum value in the given collection."
| maxIndex maxValue |
maxIndex := 1.
maxValue := self at: 1.
2 to: self size do: [:i |
(self at: i) > maxValue ifTrue: [
maxIndex := i.
maxValue := self at: i.
]
].
^ maxIndex! !
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment