go-tour/exercise-maps.go
2020-02-04 21:44:36 -06:00

21 lines
294 B
Go

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)
}