Skip to content

Instantly share code, notes, and snippets.

@meltedice
Created October 2, 2017 05:29
Show Gist options
  • Save meltedice/1cc35996c849a44347efd2deec95605c to your computer and use it in GitHub Desktop.
Save meltedice/1cc35996c849a44347efd2deec95605c to your computer and use it in GitHub Desktop.
A Tour of Go: Exercise: Maps
package main
import (
"strings"
"golang.org/x/tour/wc"
)
func WordCount(s string) map[string]int {
wordCount := make(map[string]int)
for _, word := range strings.Fields(s) {
wordCount[word] += 1
}
return wordCount
}
func main() {
wc.Test(WordCount)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment