Challenge: Improving DragonSpeak

Hello,

Here is my solution for the “Improving DragonSpeak” challenge:

private fun toDragonSpeak(phrase: String) = phrase.replace(Regex("[aeiouAEIOU]")) {
    when(it.value) {
        "a" -> "4"
        "e" -> "3"
        "i" -> "1"
        "o" -> "0"
        "u" -> "|_|"
        "A" -> "4"
        "E" -> "3"
        "I" -> "1"
        "O" -> "0"
        "U" -> "|_|"
        else -> it.value
    }
}

All I did was to add the capital cases of the characters to the list. I was just wondering if there was a “better” or “more professional” way of solving this challenge?

Thanks,
Max

My solution looked slightly different to reduce the number of cases. The Regex was the same, but I converted the value to be lowercase

private fun toDragonSpeak(phrase: String) =
    phrase.replace(Regex("[aeiouAEIOU]")) {
        when (it.value.toLowerCase()) {
            "a" -> "4"
            "e" -> "3"
            "i" -> "1"
            "o" -> "0"
            "u" -> "|_|"
            else -> it.value
        }
    }
1 Like

That’s actually a nice way to do it I think. Idk why I didn’t think of that lol. Thanks

Here is my solution