Exercise: Maps
Implement WordCount
. It should return a map of the counts of each “word” in the string s
. The wc.Test
function runs a test suite against the provided function and prints success or failure.
You might find strings.Fields helpful.
exercise-maps.go
package main
import (
"golang.org/x/tour/wc"
)
func WordCount(s string) map[string]int {
return map[string]int{"x": 1}
}
func main() {
wc.Test(WordCount)
}