Skip to content

Instantly share code, notes, and snippets.

@sivan
Created December 3, 2019 18:00
Show Gist options
  • Save sivan/e42333c2fbf1fb335e9dcb30bc05e6f2 to your computer and use it in GitHub Desktop.
Save sivan/e42333c2fbf1fb335e9dcb30bc05e6f2 to your computer and use it in GitHub Desktop.
Go Exercise: Maps
package main
import (
"golang.org/x/tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
m := make(map[string]int)
words := strings.Fields(s)
for _, word := range words {
m[word]++
}
return m
}
func main() {
wc.Test(WordCount)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment