Created
June 12, 2016 21:48
-
-
Save jordancalder/af2ec0bdc6fedcf12e4887d20185bfc9 to your computer and use it in GitHub Desktop.
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" | |
) | |
func WordCount(s string) map[string]int { | |
var words = strings.Split(s, " ") | |
var mapper map[string]int | |
mapper = make(map[string]int) | |
for _, word := range words { | |
if _, ok := mapper[word]; ok { | |
mapper[word]++ | |
} else { | |
mapper[word] = 1 | |
} | |
} | |
return mapper | |
} | |
func main() { | |
wc.Test(WordCount) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment