Skip to content

Add solution for Challenge 3 by Miniuzzo#1460

Closed
Miniuzzo wants to merge 1 commit intoRezaSi:mainfrom
Miniuzzo:challenge-3-Miniuzzo
Closed

Add solution for Challenge 3 by Miniuzzo#1460
Miniuzzo wants to merge 1 commit intoRezaSi:mainfrom
Miniuzzo:challenge-3-Miniuzzo

Conversation

@Miniuzzo
Copy link

Challenge 3 Solution

Submitted by: @Miniuzzo
Challenge: Challenge 3

Description

This PR contains my solution for Challenge 3.

Changes

  • Added solution file to challenge-3/submissions/Miniuzzo/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 Feb 27, 2026

Walkthrough

This change introduces a Manager system in Go within a solution template. It defines Employee and Manager structs with methods to add employees, remove by ID, calculate average salary, and find employees by ID, along with a main function demonstrating these operations.

Changes

Cohort / File(s) Summary
Manager System Implementation
challenge-3/submissions/Miniuzzo/solution-template.go
Adds Employee and Manager structs with fields for ID, Name, Age, and Salary. Implements four Manager methods: AddEmployee (appends), RemoveEmployee (deletes by ID), GetAverageSalary (computes mean, returns 0 if empty), and FindEmployeeByID (pointer lookup). Includes main function demonstrating creation, adding two employees, removing one, calculating average salary, and printing results.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • #1129: Implements identical Employee and Manager types with the same four methods (AddEmployee, RemoveEmployee, GetAverageSalary, FindEmployeeByID) and main function.
  • #823: Adds the same Employee and Manager structs with identical Manager methods and a matching main demonstration.
  • #879: Implements the same Employee and Manager types with the identical publicly-named methods in challenge-3/submissions/*/solution-template.go.

Poem

🐰 In Go's bright fields, a Manager hops with glee,
Employees in hand, organized and free,
Adding, removing, salaries they weigh,
Finding each bunny that hops in their way! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add solution for Challenge 3 by Miniuzzo' directly and clearly describes the main change: adding a solution file for Challenge 3.
Description check ✅ Passed The description is directly related to the changeset, explaining that it contains a Challenge 3 solution with details about the file added and testing status.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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


ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a7ac764 and aef9ade.

📒 Files selected for processing (1)
  • challenge-3/submissions/Miniuzzo/solution-template.go

Comment on lines +46 to +55
func (m *Manager) FindEmployeeByID(id int) *Employee {

for _, emp := range m.Employees {
if emp.ID == id {
return &emp
}
}

return nil
}
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 | 🟠 Major

Bug: Returns pointer to loop variable copy, not the actual slice element.

emp is a copy of each Employee in the slice. Returning &emp gives a pointer to that copy, not to the element stored in m.Employees. Any modifications through the returned pointer won't affect the original data in the Manager's slice.

Use index-based iteration to return a pointer to the actual slice element.

🐛 Proposed fix
 func (m *Manager) FindEmployeeByID(id int) *Employee {
-	
-	for _, emp := range m.Employees {
-	    if emp.ID == id {
-	        return &emp
+	for i := range m.Employees {
+	    if m.Employees[i].ID == id {
+	        return &m.Employees[i]
 	    }
 	}
-	
 	return nil
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func (m *Manager) FindEmployeeByID(id int) *Employee {
for _, emp := range m.Employees {
if emp.ID == id {
return &emp
}
}
return nil
}
func (m *Manager) FindEmployeeByID(id int) *Employee {
for i := range m.Employees {
if m.Employees[i].ID == id {
return &m.Employees[i]
}
}
return nil
}

@Miniuzzo Miniuzzo closed this by deleting the head repository Mar 4, 2026
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