Skip to content

Conversation

Be1chenok
Copy link
Contributor

Challenge 3 Solution

Submitted by: @Be1chenok
Challenge: Challenge 3

Description

This PR contains my solution for Challenge 3.

Changes

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

Testing

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

Thank you for reviewing my submission! 🚀

Copy link

coderabbitai bot commented Oct 12, 2025

Walkthrough

Adds a new Go program defining Employee and Manager types with methods to add/remove employees, compute average salary, and find employees by ID. Includes a main function demonstrating these operations by creating a Manager, manipulating employees, and printing results.

Changes

Cohort / File(s) Summary of changes
Employee management feature
challenge-3/submissions/Be1chenok/solution-template.go
Introduces Employee and Manager structs; implements AddEmployee, RemoveEmployee, GetAverageSalary, FindEmployeeByID methods; adds main demonstrating usage and printing outcomes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant main as main()
  participant mgr as Manager
  participant emp as Employee

  User->>main: Run program
  note over main: Initialize Manager
  main->>mgr: AddEmployee(emp1)
  main->>mgr: AddEmployee(emp2)
  main->>mgr: RemoveEmployee(id=...)
  main->>mgr: GetAverageSalary()
  mgr-->>main: avgSalary
  main->>mgr: FindEmployeeByID(id=...)
  alt Found
    mgr-->>main: *Employee
  else Not found
    mgr-->>main: nil
  end
  main-->>User: Print results
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

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 summarizes the primary change by stating that this pull request adds the solution for Challenge 3 authored by Be1chenok in a concise and clear manner without extraneous details.
Description Check ✅ Passed The description clearly relates to the changeset by explaining that this PR provides the Challenge 3 solution, specifies the file added, and confirms that tests pass and best practices are followed.

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

@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 details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a2868df and 026a64b.

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

Comment on lines +57 to +60
for _, e := range m.Employees {
if e.ID == id {
return &e
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Fix pointer-to-range-variable bug in FindEmployeeByID.

return &e hands back a pointer to the loop’s iteration variable, which is a copy and becomes invalid once the loop advances—callers will either read stale data or the last element inspected. Return the address of the slice element instead.

-func (m *Manager) FindEmployeeByID(id int) *Employee {
-	for _, e := range m.Employees {
-		if e.ID == id {
-			return &e
-		}
+func (m *Manager) FindEmployeeByID(id int) *Employee {
+	for i := range m.Employees {
+		if m.Employees[i].ID == id {
+			return &m.Employees[i]
+		}
📝 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 _, e := range m.Employees {
if e.ID == id {
return &e
}
func (m *Manager) FindEmployeeByID(id int) *Employee {
for i := range m.Employees {
if m.Employees[i].ID == id {
return &m.Employees[i]
}
}
return nil
}
🤖 Prompt for AI Agents
In challenge-3/submissions/Be1chenok/solution-template.go around lines 57 to 60,
the function currently returns a pointer to the range loop variable (return &e),
which yields a pointer to a copy and is invalid after the iteration; change the
loop to use the slice index (for i := range m.Employees or for i, e := range
m.Employees) and return the address of the actual slice element (e.g.
&m.Employees[i]) so callers receive a valid pointer; keep the function’s
not-found behavior (return nil) unchanged.

@RezaSi RezaSi merged commit a86a2d2 into RezaSi:main Oct 16, 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