I am trying to write an effective code to reverse Case in kotlin .
HeLLo 5worLD6 -> hEllO 6WORld5 5 and 6 are swap as they have equal difference
Initially I am trying to swap digit's but forEachIndex doesn't change in my existing list . Why?
val uniqueWords = str.split(" ").map { it.toCharArray() }
uniqueWords.forEachIndexed { index, chars ->
chars.forEachIndexed { charIndex, c ->
val endIndex = chars.lastIndex - charIndex
if(c.isDigit() && chars[endIndex].isDigit()){
chars[charIndex] = chars[endIndex]
chars[endIndex] = c
}
}
}
val mVal = uniqueWords // but it doesn't swap integers