var c = new Counter[String].from(["a", "a", "b", "b", "b", "c"])
assert c.max == "b"
If more than one max exists, the first one is returned.
# Return the element with the highest value (aka. the mode)
#
# ~~~
# var c = new Counter[String].from(["a", "a", "b", "b", "b", "c"])
# assert c.max == "b"
# ~~~
#
# If more than one max exists, the first one is returned.
fun max: nullable E do
var max: nullable Int = null
var elem: nullable E = null
for e in map.keys do
var v = map[e]
if max == null or v > max then
max = v
elem = e
end
end
return elem
end
lib/counter/counter.nit:196,2--215,4