File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
challenge-6/submissions/yz4230 Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ // Package challenge6 contains the solution for Challenge 6.
2+ package challenge6
3+
4+ import "strings"
5+
6+ func isSpace (c rune ) bool {
7+ return c == ' ' || c == '\t' || c == '\n' || c == '-'
8+ }
9+
10+ func isLetter (c rune ) bool {
11+ return ('0' <= c && c <= '9' ) || ('a' <= c && c <= 'z' ) || ('A' <= c && c <= 'Z' )
12+ }
13+
14+ func CountWordFrequency (text string ) map [string ]int {
15+ // Your implementation here
16+ m := make (map [string ]int )
17+ parts := make ([]string , 0 )
18+
19+ buf := ""
20+ for _ , c := range text {
21+ if len (buf ) > 0 && isSpace (c ) {
22+ parts = append (parts , buf )
23+ buf = ""
24+ } else if isLetter (c ) {
25+ buf += string (c )
26+ }
27+ }
28+ if len (buf ) > 0 {
29+ parts = append (parts , buf )
30+ }
31+
32+ for _ , part := range parts {
33+ m [strings .ToLower (part )]++
34+ }
35+
36+ return m
37+ }
You can’t perform that action at this time.
0 commit comments