Created
February 4, 2020 19:02
-
-
Save Eduardo-Nunes/251746939f2bfc53e541d787e1e773c0 to your computer and use it in GitHub Desktop.
String with double spacing with Kotlin
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 String.doubleSpacing(): String { | |
var self = "" | |
this.forEachIndexed { index, character -> | |
self = if (index == 0) "$character" else "$self $character" | |
} | |
return self | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment