go-learning/exercises/maps.go

21 lines
312 B
Go
Raw Normal View History

2023-07-17 09:13:08 +03:00
package main
// Exercise: https://go.dev/tour/moretypes/23
import (
//"golang.org/x/tour/wc" // Not valid in local!
"strings"
)
func WordCount(s string) map[string]int {
m := make(map[string]int)
for _, val := range strings.Fields(s) {
m[val] += 1
}
return m
}
func main() {
// wc.Test(WordCount)
}