Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fun main(args: Array<String>) {
- // val givenInput = ""
- val givenInput = "abc"
- fun invertName(name: String): String {
- require(name.isNotEmpty()) { "The string must not be empty" }
- val result = name.split("").reversed().joinToString("").substring(1)
- check(result.length == name.length) { "Input and output sized should not be different" }
- assert(name.first() == result.last()) { "The first letter \"${name.first()}\" of the input should be the last one of the output" }
- return result
- }
- print(invertName(givenInput))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement