Maps exercise!
This commit is contained in:
19
gotime/src/exercise-maps.go
Normal file
19
gotime/src/exercise-maps.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"code.google.com/p/go-tour/wc"
|
||||
)
|
||||
|
||||
func WordCount(s string) map[string]int {
|
||||
counts := make(map[string]int)
|
||||
words := strings.Fields(s)
|
||||
for _, word := range words {
|
||||
counts[word]++
|
||||
}
|
||||
return counts
|
||||
}
|
||||
|
||||
func main() {
|
||||
wc.Test(WordCount)
|
||||
}
|
Reference in New Issue
Block a user