Last active
June 13, 2018 12:14
-
-
Save thiagoolsilva/1a99ff08c3ffbf6337bcc2940742cfd6 to your computer and use it in GitHub Desktop.
This file contains 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 joinStrings(collection: Collection<String>) = joinStrings(collection = collection, separator = ",") | |
fun joinStrings( | |
collection: Collection<String>, | |
separator: String = "," | |
): String { | |
val result = StringBuffer() | |
val firstElement = 0 | |
for((index, word) in collection.withIndex()) { | |
if(index != firstElement) result.append(separator) | |
result.append(word) | |
} | |
return result.toString() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment