Skip to content

Conversation

@yudha-Dlesmana
Copy link

Challenge 3 Solution

Submitted by: @yudha-Dlesmana
Challenge: Challenge 3

Description

This PR contains my solution for Challenge 3.

Changes

  • Added solution file to challenge-3/submissions/yudha-Dlesmana/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 Dec 17, 2025

Walkthrough

A new Go solution file adds Employee and Manager types with methods for managing a collection of employees. The implementation includes functionality to add, remove, and query employees, compute average salaries, and demonstrates usage via a main function.

Changes

Cohort / File(s) Summary
New employee management solution
challenge-3/submissions/yudha-Dlesmana/solution-template.go
Introduces Employee struct with fields for ID, Name, Age, and Salary; defines Manager struct with employee collection; implements methods: AddEmployee, RemoveEmployee, GetAverageSalary, and FindEmployeeByID; includes main function demonstrating the API

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Core logic is straightforward CRUD operations on a slice
  • Average salary calculation is a basic arithmetic loop
  • No external dependencies or complex control flow
  • Single file with approximately 150–200 lines of code

Possibly related PRs

  • #818: Implements identical Employee and Manager types with the same collection management methods (AddEmployee, RemoveEmployee, GetAverageSalary, FindEmployeeByID) in a parallel solution file
  • #827: Adds the same Employee and Manager types and methods in a separate challenge-3 submission with functionally equivalent implementation
  • #879: Contributes the same solution pattern with identical types and methods across a different challenge-3 submissions directory

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 accurately describes the main change - adding a Challenge 3 solution submission from yudha-Dlesmana, which matches the changeset.
Description check ✅ Passed The description is directly related to the changeset, providing context about the Challenge 3 solution submission and the changes made.

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: 1

🧹 Nitpick comments (1)
challenge-3/submissions/yudha-Dlesmana/solution-template.go (1)

30-41: Redundant type conversion on line 40.

Since total is already declared as float64 (line 35), the conversion float64(total) is unnecessary.

Apply this diff:

-	return float64(total) / float64(len(m.Employees))
+	return total / float64(len(m.Employees))
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cbe1b92 and 55faf3d.

📒 Files selected for processing (1)
  • challenge-3/submissions/yudha-Dlesmana/solution-template.go (1 hunks)
🔇 Additional comments (6)
challenge-3/submissions/yudha-Dlesmana/solution-template.go (6)

1-3: LGTM!

The package declaration and import are correct for a standalone Go executable.


5-10: LGTM!

The Employee struct is well-defined with appropriate field types.


12-14: LGTM!

The Manager struct appropriately uses a slice to manage the employee collection.


16-19: LGTM!

The AddEmployee method correctly uses a pointer receiver and appends the employee to the slice.


43-51: Verify pointer stability after slice modifications.

The method returns a pointer to an element in the slice. If RemoveEmployee is called afterward, the underlying slice may be reallocated, potentially invalidating the pointer or causing it to point to different data. For this challenge, the implementation is acceptable, but in production code, consider returning a copy or documenting this behavior.


53-65: LGTM!

The main function effectively demonstrates all the Manager methods with clear, working examples.

Comment on lines +22 to +28
func (m *Manager) RemoveEmployee(id int) {
for i, emp := range m.Employees {
if emp.ID == id {
m.Employees = append(m.Employees[:i], m.Employees[i+1:]...)
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Missing return after removal causes iteration bugs.

The function continues iterating after modifying the slice, which can cause the next element to be skipped. After removing an employee, you should return immediately.

Apply this diff to fix the issue:

 func (m *Manager) RemoveEmployee(id int) {
 	for i, emp := range m.Employees {
 	    if emp.ID == id {
 	        m.Employees  = append(m.Employees[:i], m.Employees[i+1:]...)
+	        return
 	    }
 	}
 }

Additionally, consider returning a boolean to indicate whether removal was successful:

func (m *Manager) RemoveEmployee(id int) bool {
	for i, emp := range m.Employees {
	    if emp.ID == id {
	        m.Employees = append(m.Employees[:i], m.Employees[i+1:]...)
	        return true
	    }
	}
	return false
}
🤖 Prompt for AI Agents
In challenge-3/submissions/yudha-Dlesmana/solution-template.go around lines 22
to 28, the RemoveEmployee method keeps iterating after modifying the slice which
can skip elements; modify the function to return immediately after removing the
matching employee (add a return right after the append), and optionally change
the signature to return a bool and return true on successful removal and false
if not found (i.e., update signature, return true after the append, and return
false at end).

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.

1 participant