Write a magic function that works with a lambda with a receiver and performs any operation with a string.
Lambda with receiver
The Magic function
Report a typo
Sample Input 1:
helloSample Output 1:
OLLEWrite a program in Kotlin
fun String.magic(init: String.() -> String): String {
// Write your code here
}
fun main() {
val str = readLine()!!
val res = str.magic {
uppercase().reversed().dropLast(1)
}
println(res)
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.