go-tour/exercise-maps.go

21 lines
294 B
Go
Raw Normal View History

2020-02-05 03:44:36 +00:00
package main
import (
"strings"
"golang.org/x/tour/wc"
)
var count map[string]int
func WordCount(s string) map[string]int {
count = make(map[string]int)
for _, w := range strings.Fields(s) {
count[w]++
}
return count
}
func main() {
wc.Test(WordCount)
}