Last active
November 4, 2019 20:11
-
-
Save augustovictor/5d2befc9a9782ff5253620bb3eb63e73 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main(args: Array<String>) { | |
// val givenInput = "" | |
val givenInput = "abc" | |
fun invertName(name: String): String { | |
require(name.isNotEmpty()) { "The string must not be empty" } // IllegalArgumentException | |
val result = name.split("").reversed().joinToString("").substring(1) | |
check(result.length == name.length) { "Input and output sized should not be different" } // IllegalStateException | |
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)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment