Created
November 3, 2017 20:18
-
-
Save yurimorales/627c398132517d8145f489015ef53455 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
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