Slide 4
Slide 4 text
for i := 0; i < len(b)/2; i++ {
j := len(b) - i - 1
b[i], b[j] = b[j], b[i]
}
return string(b)
}
YouTube 3
~/gocode/src/github.com/nf/string$ go build
~/gocode/src/github.com/nf/string$ go install
~/gocode/src/github.com/nf/string$ ls ~/gocode/pkg/darwin_amd64/github.com/nf
string.a
~/gocode/src/github.com/nf/string$ cd ../hello
~/gocode/src/github.com/nf/hello$ vim hello.go
hello.go
package main
import (
"fmt"
"github.com/nf/string"
)
func main() {
fmt.Println(string.Reverse("Hello, new gopher!"))
}
YouTube 4
~/gocode/src/github.com/nf/hello$ go install
~/gocode/src/github.com/nf/hello$ hello
!rehpog wen ,olleH
~/gocode/src/github.com/nf/hello$ cd ../string
~/gocode/src/github.com/nf/string$ vim string_test.go
string_test.go
package string
import "testing"
func Test(t *testing.T) {
var tests = []struct {
s, want string
}{
{"Backward", "drawkcaB"},
{"Hello, 世界", "界世 ,olleH"},
{"", ""},
}