I’ve tried to find the solution to this particular challenge for countless hours. Not sure if I’m doing this right, but can the answer be found using subSequence or maybe subStringBeforeLast?
I’ve been reading the documentation and so far been unsuccessful, otherwise are loops the only way to solve this problem?
I found the solution to the problem, quite simple in the end, just needed to look through the kotlin documentation more thoroughly in the end.
I have found an easy way to do it because a built in function is available so why to re-invent the wheel? i.e going through loops. Simply use a built in function, please check my code.
fun main() {
val playerName = "Estragon"
val revPlayerName = playerName.reversed()
println(revPlayerName)
}
Here is another way to do it without creating a new variable:
println(playerName.reversed())