Skip to content

Instantly share code, notes, and snippets.

@funyin
Created October 16, 2022 23:05
Show Gist options
  • Save funyin/9b3ae2347de62b3f3f339ddd9a760a11 to your computer and use it in GitHub Desktop.
Save funyin/9b3ae2347de62b3f3f339ddd9a760a11 to your computer and use it in GitHub Desktop.
Reverse words in string
/**
* Given an input string, reverse the string word by word
*
* Input: "reverse words in a string"
* Output: "string a in words reverse"
*/
fun main(){
val words = "reverse words in a string"
print(words.run {
split(" ").reversed().joinToString(" ")
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment