Skip to content

Instantly share code, notes, and snippets.

@marcesher
Last active January 1, 2016 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcesher/8171076 to your computer and use it in GitHub Desktop.
Save marcesher/8171076 to your computer and use it in GitHub Desktop.
ugly-ass solution for Go wordcount map exercise
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
m := make(map [string] int)
for _, v := range strings.Fields(s) {
m[v]++
}
return m
}
func main() {
wc.Test(WordCount)
}
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
f := strings.Fields(s)
m := make(map [string] int)
for i := 0; i < len(f); i++ {
m[f[i]]++
}
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