Created
April 3, 2014 04:26
-
-
Save praveenkumar/9948258 to your computer and use it in GitHub Desktop.
Excersice: 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 ( | |
"code.google.com/p/go-tour/wc" | |
"strings" | |
) | |
func WordCount(s string) map[string]int { | |
words := strings.Fields(s) | |
m := make(map[string]int) | |
for _, v := range(words) { | |
if m[v] != 0 { | |
m[v] = m[v]+1 | |
}else { | |
m[v] = 1 | |
} | |
} | |
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