otakusenpai
09/16/2018, 1:25 PMNikky
09/16/2018, 1:37 PMval map = list.asSequence().toSet().associate { key -> key to list.count { it == key }}
sequence and toSet calls just to avoid going over each key multiple times, could proably be more efficient stillotakusenpai
09/16/2018, 1:37 PMotakusenpai
09/16/2018, 1:38 PMotakusenpai
09/16/2018, 1:38 PMNikky
09/16/2018, 1:38 PMotakusenpai
09/16/2018, 1:39 PMotakusenpai
09/16/2018, 1:39 PMNikky
09/16/2018, 1:39 PMassociate
takes the key and returns a Pair, key to value
to
is a inline function that creates a Pair, this is what the associate function turns into a mapotakusenpai
09/16/2018, 1:40 PMNikky
09/16/2018, 1:40 PMmapOf(key to value, key2 to value2)
otakusenpai
09/16/2018, 1:41 PMNikky
09/16/2018, 1:41 PMotakusenpai
09/16/2018, 1:42 PMNikky
09/16/2018, 1:42 PMotakusenpai
09/16/2018, 1:42 PMotakusenpai
09/16/2018, 1:43 PMNikky
09/16/2018, 1:46 PMNikky
09/16/2018, 1:47 PMotakusenpai
09/16/2018, 1:47 PMotakusenpai
09/16/2018, 1:47 PMotakusenpai
09/16/2018, 1:47 PMNikky
09/16/2018, 1:47 PMotakusenpai
09/16/2018, 1:48 PMotakusenpai
09/16/2018, 1:49 PMNikky
09/16/2018, 1:49 PMotakusenpai
09/16/2018, 1:49 PMNikky
09/16/2018, 1:49 PMotakusenpai
09/16/2018, 1:50 PMotakusenpai
09/16/2018, 1:50 PMotakusenpai
09/16/2018, 1:50 PMfun hasIt(dmg: Int, totalDmgMap: MutableMap<Int,Int>): Pair<Boolean,MutableMap.MutableEntry<Int,Int>> {
var found = false
var entry = MutableMap.MutableEntry
for(i in totalDmgMap) {
if(i.key == dmg) {
found = true
entry = i
}
}
return Pair(found,entry)
}`
Nikky
09/16/2018, 1:50 PMotakusenpai
09/16/2018, 1:50 PMotakusenpai
09/16/2018, 1:51 PMNikky
09/16/2018, 1:52 PMotakusenpai
09/16/2018, 1:52 PMNikky
09/16/2018, 1:53 PMNikky
09/16/2018, 1:54 PMotakusenpai
09/16/2018, 1:54 PMotakusenpai
09/16/2018, 1:55 PMNikky
09/16/2018, 1:55 PMAndreas Sinz
09/16/2018, 2:40 PMlist.groupBy { it }.mapValues { it.value.count }
Nikky
09/16/2018, 2:58 PMilya.gorbunov
09/16/2018, 9:49 PMlist.groupingBy { it }.eachCount()
http://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/each-count.html