solution - #3858
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Thanks for your hard work! 😊 There's just one critical issue left: you need to use the filter method to remove dead animals from the Animal.alive array, instead of forEach and splice. Please update your code to use Animal.alive = Animal.alive.filter(animal => animal.health > 0); after any health reduction. Once that's fixed, your solution will be perfect! 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
| Animal.alive.forEach(function (animal, index, arr) { | ||
| if (animal.health <= 0) { | ||
| arr.splice(index, 1); | ||
| } | ||
| }); |
There was a problem hiding this comment.
Issue: Removing dead animals from the Animal.alive array using forEach and splice can cause elements to be skipped and is not the preferred method. According to the checklist and override instructions, you should use the filter method to remove animals with health less than or equal to 0. Please update this logic to use Animal.alive = Animal.alive.filter(animal => animal.health > 0);.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Great job! 🎉 Your implementation in src/herbivoresAndCarnivores.js fully meets all the task requirements and constraints. The class hierarchy is correct, and both the hide and bite methods behave exactly as specified. You correctly use a single if statement in bite to check both instanceof Herbivore and !hidden, and you remove dead animals from Animal.alive using the filter method, as required. The hide method only sets hidden to true without any toggling or extra logic. There are no unnecessary files, missing files, or broken functionalities.
All previous issues have been addressed, and your code is now clean, efficient, and adheres strictly to the requirements. No further changes are needed. Well done—keep up the great work! 🚀
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
No description provided.