id/email
password
forgot password | create account
about | help | prefs
ReadingBatcode reading practice

 

 

StringsStringElements2

prev  |  next  |  chance

fun stringElements2(s: String, list: List<Int>): String =
    buildString {
        list.map { it * 2 }
            .forEach { append(s[it]) }
    }

Function Call  Return Value
stringElements2("abcdefgh", listOf(3, 2, 1, 0))
stringElements2("hello there", listOf(0, 1, 2, 4))
stringElements2("This is a test", listOf(4, 2, 2, 0))
stringElements2("How was your day?", listOf(0, 4, 4, 3, 7, 7))
stringElements2("Welcome to ReadingBat", listOf(1, 4, 2, 6, 8))

Experiment with this code on Gitpod.io or as a Kotlin Playground

⬅ Back