simple maven project for codewars katas, see https://www.codewars.com/
some notes for myself
When{}
block is essentially an advanced form of the switch-case statement
When{}
as an Expression with Default Case
return when {
year % 400 == 0 -> true
year % 100 == 0 -> false
else -> year % 4 == 0
}
// count splits the string into chars
// then check only if the char is contained in base string
// sum is done by count
str.count{x->"aeiou".contains(x)}
// returns result of compare counts.value for given key with maxOccurences
// inside it increases the value for given key
fun countFilter(x: Int) = counts.compute(x, { _, count -> count?.plus(1) ?: 1 })!! <= maxOcurrences
string.mapIndexed
converts a string into a char list with index, do what you want on char
char.toString().toLowerCase().repeat(index)
when index is 0 then it return ""
:-)
// this would be like
"Hello".mapIndexed { index, char -> char.toUpperCase() + char.toString().toLowerCase().repeat(index) }
/*
resultList[0] = "H"
resultList[1] = "Ee"
resultList[2] = "Lll"
resultList[3] = "Llll"
resultList[4] = "Ooooo"
*/
see inline comments
remember grouping on string and then eachCount on grouping