-
-
Notifications
You must be signed in to change notification settings - Fork 632
Add solution for Challenge 3 by macborowy #573
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 standalone Go program implementing Employee and Manager types with methods to add, remove, search, and compute average salary over employees. main initializes a Manager, performs operations (add, remove, average, find), and prints outcomes. Changes
Sequence Diagram(s)sequenceDiagram
participant U as main()
participant M as Manager
participant E as Employee
U->>M: AddEmployee(Employee{ID:1,...})
U->>M: AddEmployee(Employee{ID:2,...})
U->>M: RemoveEmployee(id=1)
U->>M: GetAverageSalary()
M-->>U: float64 average
U->>M: FindEmployeeByID(id=2)
alt found
M-->>U: *Employee (non-nil)
else not found
M-->>U: nil
end
U->>U: fmt.Println outputs results
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 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-3/submissions/macborowy/solution-template.go (2)
21-29
: Consider removing unnecessary parentheses.The condition on line 24 has unnecessary parentheses around
e.ID == id
. Go convention is to omit parentheses around simple conditions unless needed for grouping.Apply this diff to align with Go style conventions:
- if (e.ID == id) { + if e.ID == id {
31-43
: Consider removing unnecessary parentheses.The condition on line 33 has unnecessary parentheses around
len(m.Employees) == 0
. Go convention is to omit parentheses around simple conditions.Apply this diff to align with Go style conventions:
- if (len(m.Employees) == 0) { + if len(m.Employees) == 0 {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
challenge-3/submissions/macborowy/solution-template.go
(1 hunks)
🔇 Additional comments (4)
challenge-3/submissions/macborowy/solution-template.go (4)
5-14
: LGTM! Clean type definitions.The Employee and Manager structs are well-defined with appropriate field types for the challenge requirements.
16-19
: LGTM! Simple and correct implementation.The AddEmployee method correctly uses a pointer receiver and the append operation is idiomatic Go.
45-55
: Excellent implementation!The method correctly uses
for i := range
and takes the address of the indexed element&m.Employees[i]
rather than the loop variable. This is the proper pattern to return a pointer to a slice element and avoids common pitfalls with loop variable addresses.
57-69
: LGTM! Good demonstration of functionality.The main function clearly demonstrates all the Manager methods and provides a working example that validates the implementation.
Challenge 3 Solution
Submitted by: @macborowy
Challenge: Challenge 3
Description
This PR contains my solution for Challenge 3.
Changes
challenge-3/submissions/macborowy/solution-template.go
Testing
Thank you for reviewing my submission! 🚀