Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. fun main(args: Array<String>) {
  2. // val givenInput = ""
  3. val givenInput = "abc"
  4.  
  5. fun invertName(name: String): String {
  6. require(name.isNotEmpty()) { "The string must not be empty" }
  7. val result = name.split("").reversed().joinToString("").substring(1)
  8. check(result.length == name.length) { "Input and output sized should not be different" }
  9. assert(name.first() == result.last()) { "The first letter \"${name.first()}\" of the input should be the last one of the output" }
  10. return result
  11. }
  12.  
  13. print(invertName(givenInput))
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement