-
-
Couldn't load subscription status.
- Fork 660
Add solution for Challenge 3 by baindraraj #615
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
Add solution for Challenge 3 by baindraraj #615
Conversation
WalkthroughIntroduces a new Go program with Employee and Manager types. The Manager provides methods to add and remove employees, calculate average salary, and search employees by ID. A main function demonstrates basic operations. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 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-3/submissions/baindraraj/solution-template.go (2)
31-43: LGTM! Correct average calculation.The
GetAverageSalarymethod correctly handles the edge case of an empty employee list and computes the average salary properly.Minor: Line 42 has inconsistent spacing around the
/operator. Runninggofmtwill automatically fix this formatting.
45-54: Simplify pointer dereferencing for idiomatic Go.The logic is correct, but line 49 uses explicit pointer dereferencing
(*e).IDwhich is unnecessary in Go. The language automatically dereferences pointers when accessing struct fields.Apply this diff to use idiomatic Go syntax:
func (m *Manager) FindEmployeeByID(id int) *Employee { for indx:= range m.Employees { e := &m.Employees[indx] - if (*e).ID == id { + if e.ID == id { return e } } return nil }Minor: Line 47 has a spacing issue (
indx:= rangeshould beindx := range). Runninggofmtwill automatically fix this.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
challenge-3/submissions/baindraraj/solution-template.go(1 hunks)
🔇 Additional comments (4)
challenge-3/submissions/baindraraj/solution-template.go (4)
5-14: LGTM! Clean struct definitions.The
EmployeeandManagerstruct definitions are well-designed with appropriate field types and follow Go naming conventions.
16-19: LGTM! Correct implementation.The
AddEmployeemethod correctly appends an employee to the slice using a pointer receiver.
21-29: LGTM! Correct removal logic.The
RemoveEmployeemethod correctly removes the first employee matching the given ID using standard Go slice manipulation.
56-68: LGTM! Good demonstration of the Manager functionality.The
mainfunction correctly demonstrates all Manager methods with proper nil checking before accessing the found employee.
Challenge 3 Solution
Submitted by: @baindraraj
Challenge: Challenge 3
Description
This PR contains my solution for Challenge 3.
Changes
challenge-3/submissions/baindraraj/solution-template.goTesting
Thank you for reviewing my submission! 🚀