Created
May 24, 2024 20:02
-
-
Save rsbohn/96261438b2b32e0f049153eacc99abde to your computer and use it in GitHub Desktop.
Collection>>argmax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!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