Skip to content

Instantly share code, notes, and snippets.

@alextanhongpin
Last active September 9, 2017 01:23
Show Gist options
  • Save alextanhongpin/0b72edcffda642abcd8deba81aced0c6 to your computer and use it in GitHub Desktop.
Save alextanhongpin/0b72edcffda642abcd8deba81aced0c6 to your computer and use it in GitHub Desktop.
// This program demonstrates how to reverse string in go
package main
import "log"
func main() {
log.Println(reverse("hello world!"))
}
func reverse(s string) string {
r := []rune(s)
for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
r[i], r[j] = r[j], r[i]
}
return string(r)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment