Created
April 25, 2012 06:32
-
-
Save marcellodesales/2487270 to your computer and use it in GitHub Desktop.
Wordcount implementation on Google's GO
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 ( | |
"strings" | |
"tour/wc" | |
) | |
func WordCount(s string) map[string]int { | |
var counts = make(map[string]int) | |
for _, w := range strings.Fields(s) { | |
counts[w]++ | |
} | |
return counts | |
} | |
func main() { | |
wc.Test(WordCount) | |
} |
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
http://tour.golang.org/#44 | |
PASS | |
f("I am learning Go!") = | |
map[string]int{"am":1, "I":1, "learning":1, "Go!":1} | |
PASS | |
f("The quick brown fox jumped over the lazy dog.") = | |
map[string]int{"jumped":1, "lazy":1, "dog.":1, "brown":1, "over":1, "the":1, "fox":1, "quick":1, "The":1} | |
PASS | |
f("I ate a donut. Then I ate another donut.") = | |
map[string]int{"a":1, "I":2, "another":1, "ate":2, "donut.":2, "Then":1} | |
PASS | |
f("A man a plan a canal panama.") = | |
map[string]int{"man":1, "plan":1, "canal":1, "a":2, "A":1, "panama.":1} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment