Even the latest correct code (from 1y back, saying passed latest test) is not passing in my current online editor. I raised a issue from editor, but didn’t receive any update.
Error Prints : "
# wordcount [wordcount.test]
./word_count_test.go:15:18: tt.output undefined (type struct{description string; input string; expected Frequency} has no field or method output)
FAIL wordcount [build failed]
'/usr/local/go/bin/go test --short --json .' returned exit code 1: exit status 1
"
the code thats commented is what I wrote (still learning pls don’t judge )
the one that on top not commented is community recommended latest correct answer which doesn’t pass.
package wordcount
import (
"regexp"
"strings"
)
type Frequency map[string]int
func WordCount(phrase string) Frequency {
re := regexp.MustCompile(`\w+('\w+)?`)
count := make(Frequency)
for _, w := range re.FindAllString(strings.ToLower(phrase), -1) {
count[w]++
}
return count
}
// import "unicode"
// type Frequency map[string]int
// func WordCount(phrase string) Frequency {
// currW := ""
// isInsideWrd := false
// words := make(Frequency)
// for _, c:= range phrase{
// if unicode.IsLetter(c) || unicode.IsDigit(c){
// isInsideWrd = true
// currW += string(unicode.ToLower(c))
// }else if c == '\u0027' && isInsideWrd{
// currW += string(c)
// }else if isInsideWrd{
// isInsideWrd = false
// words[currW]++
// currW = ""
// }
// }
// if isInsideWrd{
// words[currW]++
// }
// return words
// }
If the test cases are correct and not buggy, please guide me why neither the recommended code nor my kind-of right code didn’t work. NB: my code did work in Golang playground too, although I had to make some changes to make it work without test cases.