Challenge: Frame Extension

Here’s my solution, guys. Any comments are welcome!

fun main() {
    val text = "Kotlin Programming".frameExt(5)
    println(text)
}

fun String.frameExt(padding: Int, formatChar: String = "*"): String {
    val greeting = "$this!"
    val middle = formatChar.padEnd(padding)
        .plus(greeting)
        .plus(formatChar.padStart(padding))
    val end = (0 until middle.length).joinToString("") { formatChar }
    return "$end\n$middle\n$end"
}
2 Likes