Created
August 6, 2013 18:59
-
-
Save stamler/6167530 to your computer and use it in GitHub Desktop.
Exercise 40 (Maps) from tour.golang.org
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"code.google.com/p/go-tour/wc" | |
"strings" | |
) | |
// #40: Maps Exercise | |
func WordCount(s string) map[string]int { | |
output := make(map[string]int) | |
fields := strings.Fields(s) | |
for _, sub := range fields { | |
output[sub]++ | |
} | |
return output | |
} | |
func main() { | |
wc.Test(WordCount) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment