box-o-sand/gotime/gotour-artifacts/exercise-maps/main.go

20 lines
275 B
Go
Raw Normal View History

2012-08-26 02:18:48 +00:00
package main
import (
2012-11-06 02:00:35 +00:00
"code.google.com/p/go-tour/wc"
"strings"
2012-08-26 02:18:48 +00:00
)
func WordCount(s string) map[string]int {
2012-11-06 02:00:35 +00:00
counts := make(map[string]int)
words := strings.Fields(s)
for _, word := range words {
counts[word]++
}
return counts
2012-08-26 02:18:48 +00:00
}
func main() {
2012-11-06 02:00:35 +00:00
wc.Test(WordCount)
2012-08-26 02:18:48 +00:00
}