Averages/Mode: Difference between revisions

→‎{{header|Kotlin}}: Updated example see https://github.com/dkandalov/rosettacode-kotlin for details
(→‎{{header|Kotlin}}: Updated example see https://github.com/dkandalov/rosettacode-kotlin for details)
Line 1,425:
 
=={{header|Kotlin}}==
<lang scala>//fun version<T> 1.0.6modeOf(a: Array<T>) {
fun <T> modeOf(a: Array<T>) {
val sortedByFreq = a.groupBy { it }.entries.sortedByDescending { it.value.size }
val maxFreq = sortedByFreq.first().value.size
Line 1,434 ⟶ 1,433:
else {
print("There are ${modes.size} modes with a frequency of $maxFreq, namely : ")
println(modes.map { it.key }.joinToString(", "))
}
}
Line 1,445 ⟶ 1,444:
val b = arrayOf(true, false, true, false, true, true)
println("[" + b.joinToString(", ") + "]")
modeOf(b)
}</lang>