Skip to content

Instantly share code, notes, and snippets.

@automationhacks
Created June 16, 2019 12:23
Show Gist options
  • Save automationhacks/183ceedb143a30faa476e2a61f742047 to your computer and use it in GitHub Desktop.
Save automationhacks/183ceedb143a30faa476e2a61f742047 to your computer and use it in GitHub Desktop.
Moved function outside class as first class object and use of default parameters
package _03_functions
fun getFirstWord(word: String, separator: String = " "): String {
return word.split(separator)[0]
}
fun main() {
val first = getFirstWord("Jane Doe")
println("First word: $first")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment