Created
December 3, 2019 18:00
-
-
Save sivan/e42333c2fbf1fb335e9dcb30bc05e6f2 to your computer and use it in GitHub Desktop.
Go 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
package main | |
import ( | |
"golang.org/x/tour/wc" | |
"strings" | |
) | |
func WordCount(s string) map[string]int { | |
m := make(map[string]int) | |
words := strings.Fields(s) | |
for _, word := range words { | |
m[word]++ | |
} | |
return m | |
} | |
func main() { | |
wc.Test(WordCount) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment