Skip to content

Instantly share code, notes, and snippets.

@amstee
Last active January 15, 2017 00:09
Show Gist options
  • Select an option

  • Save amstee/8fd6fbbec67366a0ff69aa7d88a8f709 to your computer and use it in GitHub Desktop.

Select an option

Save amstee/8fd6fbbec67366a0ff69aa7d88a8f709 to your computer and use it in GitHub Desktop.
An answer for the exercise maps
import (
"strings"
)
func WordCount(s string) (container map[string]int) {
fields := strings.Fields(s)
container = make(map[string]int)
for i := 0; i < len(fields); i++ {
if _, ok := container[fields[i]]; ok == true {
container[fields[i]] += 1
} else {
container[fields[i]] = 1
}
}
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment