Last active
July 21, 2017 05:51
-
-
Save Yuichiroh/33e7444b390be6142ede90632f648708 to your computer and use it in GitHub Desktop.
argmax in Scala
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
implicit class ArgmaxColl[A, CC[X] <: Seq[X]](val coll: CC[A]) extends AnyVal { | |
def argmax(implicit o:Ordering[A]): Int = coll.indices.maxBy(coll) | |
} | |
val as = scala.util.Random.shuffle(1 to 10) | |
as.argmax |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment