Created
March 18, 2015 17:19
-
-
Save toothrot/2e18e378c12fbb1f9db2 to your computer and use it in GitHub Desktop.
Exercise: Maps
This file contains 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
// 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