Skip to content

Add solution for Challenge 6 by manik23 - #1062

Merged
github-actions[bot] merged 2 commits into
RezaSi:mainfrom
manik23:challenge-6-manik23-1767528342
Apr 14, 2026
Merged

github-actions[bot] merged 2 commits into
RezaSi:mainfrom
manik23:challenge-6-manik23-1767528342

Conversation

@manik23

@manik23 manik23 commented Jan 4, 2026

Copy link
Copy Markdown
Contributor

Challenge 6 Solution

Submitted by: @manik23
Challenge: Challenge 6

Description

This PR contains my solution for Challenge 6.

Changes

  • Added solution file to challenge-6/submissions/manik23/solution-template.go

Testing

  • Solution passes all test cases
  • Code follows Go best practices

Thank you for reviewing my submission! 🚀

@coderabbitai

coderabbitai Bot commented Jan 4, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

Adds a new exported function CountWordFrequency to the challenge6 package that computes a case-insensitive frequency map of words in a given text. The function normalizes input by converting to lowercase, removing apostrophes, and splitting on non-alphanumeric characters via regex pattern.

Changes

Cohort / File(s) Summary
Word Frequency Counter Implementation
challenge-6/submissions/manik23/solution-template.go
Added CountWordFrequency(text string) map[string]int function that normalizes text (lowercase conversion, apostrophe removal), splits on non-alphanumeric characters using regex, and returns a frequency map of words

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • #799: Implements the same CountWordFrequency function in challenge6 with identical normalization and word-counting behavior
  • #841: Adds CountWordFrequency(text string) map[string]int to challenge6 in a different submission file
  • #649: Adds CountWordFrequency to challenge6 with nearly identical case-insensitive word-counting and apostrophe-stripping logic

Pre-merge checks

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add solution for Challenge 6 by manik23' accurately describes the main change: adding a new solution file for Challenge 6.
Description check ✅ Passed The description is directly related to the changeset, clearly explaining that it contains a Challenge 6 solution submission with file additions and testing claims.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (5)
challenge-6/submissions/manik23/solution-template.go (5)

4-8: Remove leftover template comment.

The comment on line 5 appears to be from the template and should be removed for cleaner production code.

🔎 Proposed fix
 import (
-	// Add any necessary imports here
 	"strings"
 	"regexp"
 )

10-20: Consider clarifying apostrophe handling in documentation.

The documentation mentions that punctuation is ignored, but doesn't explicitly state that apostrophes are removed during preprocessing. This means "don't" becomes "dont" as a single word. Consider adding a note about this behavior for clarity.


26-26: Add spaces after commas for Go conventions.

Line 26 should have spaces after commas: strings.ReplaceAll(text, "'", ""). Running go fmt will automatically fix this and other formatting issues in the file.


28-28: Move regex compilation to package level for better performance.

Compiling the regular expression on every function call is inefficient. For functions that may be called frequently, consider compiling the regex once at the package level.

🔎 Proposed refactor

At the package level (before the function):

+var wordSplitRegex = regexp.MustCompile(`[^a-z0-9]+`)
+
 // CountWordFrequency takes a string containing multiple words and returns

Then update line 32:

-    re := regexp.MustCompile(`[^a-zA-Z0-9]`)
-    
-  
-    
-    words := re.Split(text,-1)
+    words := wordSplitRegex.Split(text, -1)

Note: The pattern is also simplified to [^a-z0-9]+ since the text is already lowercase, and the + makes it slightly more efficient by treating consecutive delimiters as one.


21-46: Consider running go fmt to standardize formatting.

The function logic is correct and handles edge cases appropriately (empty strings, case-insensitivity). However, there are several formatting inconsistencies:

  • Excessive blank lines (lines 22, 27, 30-31, 35, 41, 43-44)
  • Missing spaces after commas in function calls (lines 26, 32, 34)

Running go fmt or gofmt will automatically fix these formatting issues to match Go conventions.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 669bf54 and af7d24a.

📒 Files selected for processing (1)
  • challenge-6/submissions/manik23/solution-template.go

@github-actions
github-actions Bot merged commit f19535d into RezaSi:main Apr 14, 2026
6 checks passed
@github-actions

Copy link
Copy Markdown

🎉 Auto-merged!

This PR was automatically merged after 2 days with all checks passing.

Thank you for your contribution, @manik23!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants