Last active
February 7, 2019 07:30
-
-
Save renaudcerrato/0c10ee7e8d9f125ab30e1b1aadd7235e to your computer and use it in GitHub Desktop.
Kotlin Functions, advanced
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 join(strings: Collection<String>, separator: String = " ", | |
prefix: String = "", postfix: String = "") : String | |
{ | |
val result = StringBuilder(prefix) | |
for((index, element) in strings.withIndex()) { | |
if(index > 0) result.append(separator) | |
result.append(element) | |
} | |
result.append(postfix) | |
return result.toString() | |
} | |
join(list) | |
join(list, separator = ",") | |
join(list, prefix = "(", postfix = ")") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment