add task solution - #3915
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
There are two critical issues that must be addressed before approval:
-
Incorrect removal from
Animal.alive: The code usesindexOfandspliceto remove dead animals, but the requirements and checklist explicitly state that you must useArray.prototype.filterfor this purpose. This is a technical constraint and a core requirement. -
Incorrect removal condition: Animals are only removed from
Animal.alivewhen theirhealth === 0, but the requirement is to remove them whenhealth <= 0. This means animals with negative health could remain in the array, which breaks the contract thatAnimal.aliveonly contains alive animals.
To fix these issues:
- Refactor your removal logic to use
filter, for example:Animal.alive = Animal.alive.filter(animal => animal.health > 0);
- Ensure this filtering happens after any change to an animal's health, and that it removes all animals with
health <= 0.
Everything else in your implementation looks solid, especially your use of inheritance and method logic. Once you address these blockers, your code should meet all requirements. Keep up the good work!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
| const index = Animal.alive.indexOf(animal); | ||
|
|
||
| if (index > -1) { | ||
| Animal.alive.splice(index, 1); |
There was a problem hiding this comment.
This violates checklist item: 'The Animal.alive array must be updated using Array.prototype.filter to remove dead animals (with health <= 0). Avoid using nested loops or indexOf + splice for this purpose.'
You are using indexOf and splice instead of filter to remove dead animals from Animal.alive.
| if (animal instanceof Herbivore && !animal.hidden) { | ||
| animal.health -= 50; | ||
|
|
||
| if (animal.health === 0) { |
There was a problem hiding this comment.
This violates the requirement that animals must be removed from Animal.alive when their health is less than or equal to 0. Your code only removes them when health === 0. It should be health <= 0.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
All core requirements for the Animal, Herbivore, and Carnivore classes are fully met. The code correctly implements ES6 class inheritance, property management, and the required methods (hide and bite) with proper logic. The Animal.alive array is always up to date, and all technical and stylistic constraints are satisfied. There are no critical issues or blockers. Great job on a clean and robust implementation!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
No description provided.