Skip to content

Instantly share code, notes, and snippets.

@blakesmith
Created July 4, 2012 20:04
Show Gist options
  • Save blakesmith/3049269 to your computer and use it in GitHub Desktop.
Save blakesmith/3049269 to your computer and use it in GitHub Desktop.
Go Tour: Exercise: Exercise: Maps - My solution
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
counts := make(map[string]int)
splitStrings := strings.Split(s, " ")
for i := 0; i < len(splitStrings); i++ {
counts[splitStrings[i]] += 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