Last active
January 1, 2016 16:29
-
-
Save marcesher/8171076 to your computer and use it in GitHub Desktop.
ugly-ass solution for Go wordcount map exercise
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 { | |
m := make(map [string] int) | |
for _, v := range strings.Fields(s) { | |
m[v]++ | |
} | |
return m | |
} | |
func main() { | |
wc.Test(WordCount) | |
} |
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 { | |
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