Solution - #3914
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
The implementation is very close, but there is a critical blocker: the requirement to update Animal.alive using Array.prototype.filter to remove dead animals (those with health <= 0) is not met. Instead, the code uses indexOf and splice inside the die() method, and checks for presence before removal. This directly violates the explicit checklist item and technical constraints for this task.
What needs fixing:
- Refactor the logic so that after any health change (especially after a bite),
Animal.aliveis reassigned usingfilterto exclude animals withhealth <= 0. - Remove all uses of
indexOfandsplicefor this purpose, and do not check for presence before filtering.
For example, you might update the array like this:
Animal.alive = Animal.alive.filter(animal => animal.health > 0);Once you make this change, your code will fully comply with the requirements. You did a great job with the rest of the class structure and method logic—just this one technical detail needs to be addressed. Keep going, you're almost there!
✨ 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(this); | ||
|
|
||
| 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 (those with health <= 0)." The current implementation uses indexOf and splice in the die() method, which is not allowed. You must use filter to update Animal.alive after an animal's health drops to 0 or below.
|
I corrected the solution, but the original requirements ( |
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
All core requirements and checklist items are fully met. Your implementation of the Animal, Herbivore, and Carnivore classes is correct, uses ES6 class syntax, and handles all specified behaviors (including hiding, biting, and alive tracking) exactly as described. The use of Array.prototype.filter for managing the Animal.alive array is spot-on, and all technical constraints are respected. Great job—your code is clear, maintainable, and ready for the next steps!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
No description provided.