Skip to content

Instantly share code, notes, and snippets.

@jchung05
Last active September 25, 2018 00:47
Show Gist options
  • Save jchung05/419d8dae2dd3ea4af44c93ac4729ccaf to your computer and use it in GitHub Desktop.
Save jchung05/419d8dae2dd3ea4af44c93ac4729ccaf to your computer and use it in GitHub Desktop.
An attempt at the A Tour of Go Maps exercise
package main
import (
"golang.org/x/tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
ret := make(map[string]int)
words := strings.Fields(s)
for word := range words {
ret[words[word]]++
}
return ret
}
func main() {
wc.Test(WordCount)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment