-
-
Notifications
You must be signed in to change notification settings - Fork 749
Add solution for Challenge 2 by cckwes #847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughAdds a new Go program that implements a Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related PRs
Pre-merge checks❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
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.
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 (2)
challenge-2/submissions/cckwes/solution-template.go (2)
9-21: main flow is correct; only minor robustness tweaks are possibleThe stdin → process → stdout flow is clean and idiomatic for this challenge. If this were used beyond the kata, you might:
- Loop on
scanner.Scan()to handle multiple lines.- Check
scanner.Err()after the scan for input errors.For the current challenge, this is fine as-is.
23-34: ReverseString is correct and Unicode-safe; in-place reversal would avoid an extra allocationImplementation is clear, handles multi‑byte runes correctly, and is easy to read. If you want to tighten it further, you could reverse the
runesslice in place instead of allocatingresult, which saves one allocation/copy while keeping the same behavior:-func ReverseString(s string) string { - runes := []rune(s) - stringLength := len(runes) - result := make([]rune, stringLength) - - for i := 0; i < stringLength; i++ { - result[stringLength - 1 - i] = runes[i] - } - - return string(result) -} +func ReverseString(s string) string { + runes := []rune(s) + for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 { + runes[i], runes[j] = runes[j], runes[i] + } + return string(runes) +}Not required for correctness, just a small optimization.
Challenge 2 Solution
Submitted by: @cckwes
Challenge: Challenge 2
Description
This PR contains my solution for Challenge 2.
Changes
challenge-2/submissions/cckwes/solution-template.goTesting
Thank you for reviewing my submission! 🚀