Skip to content

Instantly share code, notes, and snippets.

@toothrot
Created March 18, 2015 17:19
Show Gist options
  • Save toothrot/2e18e378c12fbb1f9db2 to your computer and use it in GitHub Desktop.
Save toothrot/2e18e378c12fbb1f9db2 to your computer and use it in GitHub Desktop.
Exercise: Maps
// https://tour.golang.org/moretypes/19
package main
import (
"golang.org/x/tour/wc"
)
import "strings"
func WordCount(s string) map[string]int {
counts := make(map[string]int)
words := strings.Fields(s)
for _, word := range words {
counts[word] += 1
}
return counts
}
func main() {
wc.Test(WordCount)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment