Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

task solution #2924

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

task solution #2924

wants to merge 1 commit into from

Conversation

D0dgerJ
Copy link

@D0dgerJ D0dgerJ commented Jan 11, 2025

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Great job on implementing the task requirements and following best practices! 🎉 While there are a couple of areas for improvement, such as handling empty arrays in getNewTodoId and ensuring getUserById doesn't assume a user will always be found, these are minor issues that don't significantly impact the functionality. Keep up the good work, and consider these enhancements for future robustness! 😊

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

Comment on lines +15 to +16
const getUserById = (userId: number): User =>
usersFromServer.find(user => user.id === userId) as User;

Choose a reason for hiding this comment

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

The getUserById function uses a type assertion (as User) which assumes that a user will always be found. If userId does not exist in usersFromServer, this will result in a runtime error. Consider handling the case where the user is not found, perhaps by returning null or a default user object.

Comment on lines +10 to +12
const maxId = Math.max(...todos.map(todo => todo.id));

return maxId + 1;

Choose a reason for hiding this comment

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

The getNewTodoId function does not handle the case where the todos array is empty. Using Math.max on an empty array will result in -Infinity, which will cause the new ID to be NaN. Consider adding a check for an empty array and returning 1 or another default ID in that case.

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