mode

fun <T> Iterable<T>.mode(): Set<T>(source)

Returns the mode (most frequently occurring values) of this iterable.

The mode is the set of values that appear most often. If multiple values share the highest frequency, all of them are returned (multimodal). Works with any type that supports equality checks, not just numeric types.

NaN handling (for Double): Each NaN is treated as a unique value because NaN != NaN per IEEE 754. NaN values will not be grouped together and will not appear as the mode unless no other value is more frequent. Filter NaN values before calling if that is not desired.

Example:

listOf(1.0, 2.0, 2.0, 3.0).mode()       // setOf(2.0)
listOf(1.0, 1.0, 2.0, 2.0).mode() // setOf(1.0, 2.0)
listOf("a", "b", "b", "c").mode() // setOf("b")

Return

a Set containing all values with the highest frequency.