Created
July 11, 2018 17:10
-
-
Save TonPC64/967216762fa486fb0280f6456e9aa1b3 to your computer and use it in GitHub Desktop.
[MapHomework] มี type WordsCount ที่มี methods ต่างๆ แต่ยังไม่สมบูรณ์ ทำให้สมบูรณ์ที
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