go-tour/wc.go

20 lines
278 B
Go

package main
import (
"golang.org/x/tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
var wc map[string]int = make(map[string]int)
var str[]string = strings.Fields(s)
for _, val := range str {
wc[val]++
}
return wc
}
func main() {
wc.Test(WordCount)
}