Created
July 11, 2018 17:08
-
-
Save TonPC64/9812041081582f74ab986730d347c3f8 to your computer and use it in GitHub Desktop.
การบ้านเรื่อง map
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 ( | |
"fmt" | |
"strings" | |
) | |
func main() { | |
wc := NewWordCount() | |
wc = wc.AddWord("I am") | |
wc.PrintAll() | |
} | |
type WordsCount map[string]WordCount | |
type WordCount struct { | |
Count int | |
Length int | |
} | |
func NewWordCount() WordsCount { | |
return make(WordsCount) | |
} | |
func (wc WordsCount) AddWord(s string) WordsCount { | |
for _, str := range strings.Fields(s) { | |
wc[str] = WordCount{ | |
Count: 0, | |
Length: 0, | |
} | |
} | |
return wc | |
} | |
func (wc WordsCount) MaxWordCount() (string, int) { | |
return "", 0 | |
} | |
func (wc WordsCount) MinWordCount() (string, int) { | |
return "", 0 | |
} | |
func (wc WordsCount) LongestWord() (string, int) { | |
return "", 0 | |
} | |
func (wc WordsCount) ShortestWord() (string, int) { | |
return "", 0 | |
} | |
func (wc WordsCount) PrintAll() { | |
for key, value := range wc { | |
fmt.Println("Key:", key, "Value:", value) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment