Add solution for Challenge 6 by clgp-aint-cool#1563
Add solution for Challenge 6 by clgp-aint-cool#1563github-actions[bot] merged 2 commits intoRezaSi:mainfrom
Conversation
WalkthroughA new Go submission file was added to the challenge-6 directory containing a Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 69fc28ed-6374-40fa-a672-da70b9811ef4
📒 Files selected for processing (1)
challenge-6/submissions/clgp-aint-cool/solution-template.go
| for _, word := range strings.Fields(text) { | ||
| word = strings.ToLower(word) | ||
| word = strings.Trim(word, ".,!?\"';:-()[]{}") | ||
| wordFreq[word]++ | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
In Go's standard library, does strings.Trim remove cutset characters only from the beginning and end of a string (and not from the middle)?
💡 Result:
Yes. In Go’s standard library, strings.Trim(s, cutset) only removes characters in cutset from the start and end of s (“all leading and trailing Unicode code points contained in cutset removed”)—it does not remove matching characters from the middle of the string. [1]
Source: [1]
🏁 Script executed:
cat -n challenge-6/submissions/clgp-aint-cool/solution-template.go | head -35Repository: RezaSi/go-interview-practice
Length of output: 1391
Normalization misses non-trimmed characters and can count empty keys.
The function contract (lines 14–17) requires that "all punctuation, spaces, and other non-alphanumeric characters are ignored." However, line 28's strings.Trim() only removes the specified punctuation from token boundaries, leaving internal non-alphanumeric characters untouched. For example, characters like / in "go/go" remain inside the token, violating the contract. Additionally, line 29 can increment wordFreq[""] when a token consists entirely of characters in the trim set.
Use strings.Map() with unicode.IsLetter() and unicode.IsDigit() to treat all non-alphanumeric characters as separators, ensuring proper normalization.
|
🎉 Auto-merged! This PR was automatically merged after 2 days with all checks passing. Thank you for your contribution, @clgp-aint-cool! |
Challenge 6 Solution
Submitted by: @clgp-aint-cool
Challenge: Challenge 6
Description
This PR contains my solution for Challenge 6.
Changes
challenge-6/submissions/clgp-aint-cool/solution-template.goTesting
Thank you for reviewing my submission! 🚀