From e48569cc706b0c365bcff36c018d27a3569cbc81 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Sat, 25 Aug 2012 22:18:48 -0400 Subject: [PATCH] Maps exercise! --- gotime/src/exercise-maps.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 gotime/src/exercise-maps.go diff --git a/gotime/src/exercise-maps.go b/gotime/src/exercise-maps.go new file mode 100644 index 0000000..9d6f71a --- /dev/null +++ b/gotime/src/exercise-maps.go @@ -0,0 +1,19 @@ +package main + +import ( + "strings" + "code.google.com/p/go-tour/wc" +) + +func WordCount(s string) map[string]int { + counts := make(map[string]int) + words := strings.Fields(s) + for _, word := range words { + counts[word]++ + } + return counts +} + +func main() { + wc.Test(WordCount) +}