Ad
  • Custom User Avatar

    Though your setup will most likely work,
    a more Kotlin-ish solution would be:

    fun howOld(s: String): Int {
            return s[0].digitToInt()
        }
    

    I'd also leave out the class for the solution setup and just take the function.

    The test can also easily be written in a loop.

    @Test
        internal fun testHowOld() {
            for (i in 1..9) {
                assertEquals(i, howOld("$i years old"))
            }
        }
    

    Let me know what you think :)