Skip to content

Add solution for Challenge 3 by alimkinpark#1637

Open
alimkinpark wants to merge 1 commit into
RezaSi:mainfrom
alimkinpark:challenge-3-alimkinpark
Open

Add solution for Challenge 3 by alimkinpark#1637
alimkinpark wants to merge 1 commit into
RezaSi:mainfrom
alimkinpark:challenge-3-alimkinpark

Conversation

@alimkinpark
Copy link
Copy Markdown
Contributor

Challenge 3 Solution

Submitted by: @alimkinpark
Challenge: Challenge 3

Description

This PR contains my solution for Challenge 3.

Changes

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

Testing

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

Thank you for reviewing my submission! 🚀

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 30, 2026

Walkthrough

Added a complete Go implementation of an Employee data model and Manager container with methods for adding/removing employees, calculating average salary, and finding employees by ID. A main function demonstrates the functionality with sample operations.

Changes

Cohort / File(s) Summary
Employee Manager Implementation
challenge-3/submissions/alimkinpark/solution-template.go
Added Employee struct with ID, Name, and Salary fields. Added Manager struct with employee slice. Implemented AddEmployee (appends employee), RemoveEmployee (removes by ID), GetAverageSalary (computes mean salary), and FindEmployeeByID (returns pointer to employee). Added main function demonstrating creation, population, removal, and queries of manager.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Poem

🐰 A Manager comes to life with grace,
With Employees filling up their space,
Add, remove, and average they may,
Find by ID throughout the day,
Go code hops along so bright! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 passed)
Check name Status Explanation
Title check ✅ Passed The title directly describes the main change: adding a solution file for Challenge 3 by a specific contributor.
Description check ✅ Passed The description is relevant to the changeset, clearly indicating this is a Challenge 3 solution submission with details about the changes made.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.11.4)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


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
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
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/alimkinpark/solution-template.go (1)

55-58: Prefer &m.Employees[i] over &e to return a pointer to the actual slice element

While the returned pointer is only read in tests, returning &m.Employees[i] preserves correct pointer semantics and points to the actual slice storage rather than a range-loop copy. This ensures the caller gets a direct reference to the slice element, maintaining the expected contract.

Suggested fix
-	for _, e := range m.Employees {
-	    if e.ID == id {
-	        return &e
-	    }    
+	for i := range m.Employees {
+		if m.Employees[i].ID == id {
+			return &m.Employees[i]
+		}
 	}

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: afe4e96b-edca-4e43-bfcb-f557f63170b7

📥 Commits

Reviewing files that changed from the base of the PR and between bf844ae and 174d577.

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

Comment on lines +25 to +31
for i, e := range m.Employees {
if e.ID == id {
m.Employees = append(m.Employees[:i],
m.Employees[i+1:]...)
}
return
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

RemoveEmployee returns too early and skips most employees

Line 30 returns on the first loop iteration even when IDs don’t match, so only index 0 is effectively checked.

Suggested fix
 func (m *Manager) RemoveEmployee(id int) {
 	// TODO: Implement this method
-	for i, e := range m.Employees {
-	    if e.ID == id {
-	        m.Employees = append(m.Employees[:i], 
-	        m.Employees[i+1:]...)
-	    }
-	    return
+	for i, e := range m.Employees {
+		if e.ID == id {
+			m.Employees = append(m.Employees[:i], m.Employees[i+1:]...)
+			return
+		}
 	}
 }
📝 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
for i, e := range m.Employees {
if e.ID == id {
m.Employees = append(m.Employees[:i],
m.Employees[i+1:]...)
}
return
}
func (m *Manager) RemoveEmployee(id int) {
// TODO: Implement this method
for i, e := range m.Employees {
if e.ID == id {
m.Employees = append(m.Employees[:i], m.Employees[i+1:]...)
return
}
}
}

@github-actions
Copy link
Copy Markdown

⚠️ Auto-merge failed

Could not automatically merge this PR: Resource not accessible by integration

A maintainer will need to merge manually.

2 similar comments
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

⚠️ Auto-merge failed

Could not automatically merge this PR: Resource not accessible by integration

A maintainer will need to merge manually.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

⚠️ Auto-merge failed

Could not automatically merge this PR: Resource not accessible by integration

A maintainer will need to merge manually.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

👋 Action needed for auto-merge

This PR cannot be auto-merged because "Allow edits from maintainers" is enabled. This is a GitHub limitation with automated workflows.

To fix: Please uncheck "Allow edits from maintainers" in the PR sidebar (under the reviewers section), and the PR will be auto-merged in the next cycle.

Alternatively, a maintainer can merge this manually.

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