-
-
Notifications
You must be signed in to change notification settings - Fork 752
Add solution for Challenge 2 by elecycele #794
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,38 @@ | ||||||
| package main | ||||||
|
|
||||||
| import ( | ||||||
| "bufio" | ||||||
| "fmt" | ||||||
| "os" | ||||||
| ) | ||||||
|
|
||||||
| func main() { | ||||||
| // Read input from standard input | ||||||
| scanner := bufio.NewScanner(os.Stdin) | ||||||
| if scanner.Scan() { | ||||||
| input := scanner.Text() | ||||||
|
|
||||||
| // Call the ReverseString function | ||||||
| output := ReverseString(input) | ||||||
|
|
||||||
| // Print the result | ||||||
| fmt.Println(output) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // ReverseString returns the reversed string of s. | ||||||
| func ReverseString(s string) string { | ||||||
| // TODO: Implement the function | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the TODO comment. The function is fully implemented, so the TODO comment should be removed. Apply this diff: - // TODO: Implement the function
runes := []rune(s)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| runes := []rune(s) | ||||||
| i := 0 | ||||||
| j := len(s) -1 | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical bug: Use Line 28 uses Example: The string Apply this diff to fix the bug: - j := len(s) -1
+ j := len(runes) - 1📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
|
|
||||||
|
|
||||||
| for i < j { | ||||||
| runes[i], runes[j] = runes[j], runes[i] | ||||||
|
|
||||||
| i++ | ||||||
| j-- | ||||||
| } | ||||||
| return string(runes) | ||||||
| } | ||||||
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.
Consider adding error handling for scanner.
The code doesn't check for scanner errors after
Scan()returns. While this works for valid input, it silently ignores any I/O errors.Apply this diff to add error handling:
func main() { // Read input from standard input scanner := bufio.NewScanner(os.Stdin) if scanner.Scan() { input := scanner.Text() // Call the ReverseString function output := ReverseString(input) // Print the result fmt.Println(output) } + if err := scanner.Err(); err != nil { + fmt.Fprintf(os.Stderr, "Error reading input: %v\n", err) + os.Exit(1) + } }📝 Committable suggestion
🤖 Prompt for AI Agents