Skip to content

Conversation

@AlexO-85
Copy link
Contributor

@AlexO-85 AlexO-85 commented Nov 6, 2025

Challenge 3 Solution

Submitted by: @AlexO-85
Challenge: Challenge 3

Description

This PR contains my solution for Challenge 3.

Changes

  • Added solution file to challenge-3/submissions/AlexO-85/solution-template.go

Testing

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

Thank you for reviewing my submission! 🚀

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 6, 2025

Walkthrough

A new Go solution file is introduced that defines an Employee type with ID, Name, Age, and Salary fields, along with a Manager type containing a slice of employees. Four manager methods implement employee lifecycle operations: adding, removing, average salary calculation, and ID-based lookup.

Changes

Cohort / File(s) Summary
New solution submission
challenge-3/submissions/AlexO-85/solution-template.go
Introduces Employee struct with ID, Name, Age, Salary fields; Manager struct with employee slice; implements AddEmployee, RemoveEmployee, GetAverageSalary, and FindEmployeeByID methods; includes main routine demonstrating usage

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Straightforward data types and CRUD operations with consistent patterns across methods
  • Proper nil-checking in FindEmployeeByID and zero-division guard in GetAverageSalary
  • RemoveEmployee uses single-pass iteration to locate and delete first match

Possibly related PRs

Pre-merge checks

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add solution for Challenge 3 by AlexO-85' directly and clearly summarizes the main change: adding a solution submission for Challenge 3.
Description check ✅ Passed The description is clearly related to the changeset, providing context about the challenge submission, listing the key file added, and mentioning testing and code quality claims.

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 (3)
challenge-3/submissions/AlexO-85/solution-template.go (3)

21-29: RemoveEmployee logic is correct.

The slice manipulation correctly removes the first matching employee. Consider these optional style improvements:

  • Line 24: Parentheses around if conditions are not idiomatic in Go.
  • Line 26: The semicolon after break is unnecessary.

Apply this diff for Go style conventions:

-	    if(e.ID == id){
+	    if e.ID == id {
 	        m.Employees = append(m.Employees[:i], m.Employees[i+1:]...)
-	        break;
+	        break
 	    }

31-48: GetAverageSalary correctly handles edge cases.

The method properly guards against division by zero. Consider these optional refinements:

  • Line 37: Parentheses around if conditions are not idiomatic in Go.
  • Line 45: Reuse countEmployees instead of calling len() again for consistency.

Apply this diff for minor improvements:

-    if(countEmployees == 0){
+    if countEmployees == 0 {
         return sumSalary
     }
     
 	for _, e := range m.Employees {
 	    sumSalary += e.Salary
 	}
 	
-	avgSalary := sumSalary / float64(len(m.Employees))
+	avgSalary := sumSalary / float64(countEmployees)
 	
 	return avgSalary

50-58: FindEmployeeByID correctly returns a pointer.

The method appropriately returns a pointer to the employee or nil if not found. Optional style improvement:

  • Line 53: Parentheses around if conditions are not idiomatic in Go.

Apply this diff for Go style conventions:

-	    if(m.Employees[i].ID == id){
+	    if m.Employees[i].ID == id {
 	        return &m.Employees[i]
 	    }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1a06951 and aa5c7c9.

📒 Files selected for processing (1)
  • challenge-3/submissions/AlexO-85/solution-template.go (1 hunks)
🔇 Additional comments (4)
challenge-3/submissions/AlexO-85/solution-template.go (4)

5-10: LGTM! Employee struct is well-defined.

The Employee struct with ID, Name, Age, and Salary fields is appropriate and follows Go naming conventions.


12-14: LGTM! Manager struct is correctly defined.

The Manager struct appropriately contains a slice of employees.


16-19: LGTM! AddEmployee implementation is correct.

The method correctly uses append to add employees, which is the idiomatic Go approach.


60-72: LGTM! Main function demonstrates the solution effectively.

The main function appropriately exercises all Manager methods and produces correct output.

@RezaSi RezaSi merged commit d6389a2 into RezaSi:main Nov 6, 2025
5 checks passed
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