Skip to content

Instantly share code, notes, and snippets.

@yurimorales
Created November 3, 2017 20:18
Show Gist options
  • Save yurimorales/627c398132517d8145f489015ef53455 to your computer and use it in GitHub Desktop.
Save yurimorales/627c398132517d8145f489015ef53455 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"strings"
)
func reverseString(s string) string {
if len(s) > 0 {
newSlice := strings.Split(s, " ")
reverse := []string{}
for i := range newSlice {
parts := newSlice[len(newSlice)-1-i]
reverse = append(reverse, parts)
}
return strings.Join(reverse, " ")
}else{
return "invalid string"
}
}
func main (){
var oldString string = "O rato roeu a roupa do rei de roma."
newString := reverseString(oldString)
fmt.Println(newString)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment