Created
February 13, 2018 21:56
-
-
Save joshskeen/172d170758f7a32aa20bbfd0cab84259 to your computer and use it in GitHub Desktop.
This file contains hidden or 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>) { | |
orderDrink("ale,dragon's breath,5.932") | |
} | |
private fun orderDrink(drinkData: String) { | |
val indexOfClosingBracket = drinkData.indexOf("]") | |
//type | |
val drinkType = drinkData.substringBefore(",") | |
//price | |
val drinkPrice = drinkData.substringAfterLast(",") | |
val indexOfFirst = drinkData.indexOfFirst { it == ',' } | |
val indexOfLast = drinkData.indexOfLast { it == ',' } | |
//drinkName | |
val drinkName = drinkData.substring(indexOfFirst + 1 until indexOfLast) | |
//a faster way to show this would be .split - also would be more real world..and frankly | |
// possibly easier to understand as well with a little bit of explanation that we'll see all the details of list | |
println("SimTavern -> orderDrink type: $drinkType , name: $drinkName , price: $drinkPrice") | |
val bartenderRemarks = | |
"Ah, a delicious $drinkType...nothing satisfies like a $drinkName." | |
println("Bartender: $bartenderRemarks") | |
println("You consume a $drinkName.") | |
println("You exclaim: " + l33tSpeak("${drinkName}s are delicious!")) | |
} | |
private fun l33tSpeak(nameOfDrink: String) = | |
nameOfDrink.replace(Regex("[aeiou]")) { | |
when (it.value) { | |
"a" -> "4" | |
"e" -> "3" | |
"i" -> "1" | |
"o" -> "0" | |
else -> it.value | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment