Skip to content

Instantly share code, notes, and snippets.

@augustovictor
Last active November 4, 2019 20:11
Show Gist options
  • Save augustovictor/5d2befc9a9782ff5253620bb3eb63e73 to your computer and use it in GitHub Desktop.
Save augustovictor/5d2befc9a9782ff5253620bb3eb63e73 to your computer and use it in GitHub Desktop.
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