Skip to content

Solution - #4462

Open
polina3107 wants to merge 2 commits into
mate-academy:masterfrom
polina3107:develop
Open

Solution#4462
polina3107 wants to merge 2 commits into
mate-academy:masterfrom
polina3107:develop

Conversation

@polina3107

Copy link
Copy Markdown

No description provided.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Summary

Your implementation has two critical violations that must be fixed:

  1. Missing instanceof Herbivore check in the bite method - carnivores can currently bite other carnivores, which violates the task requirement. Add if (!(herb instanceof Herbivore)) return; at the start of the bite method.

  2. Violates checklist item #1 - you use indexOf + splice to remove dead animals, but the checklist explicitly requires using Animal.alive = Animal.alive.filter(animal => animal.health > 0); instead.

  3. Death condition issue - using === 0 instead of <= 0 means animals with health below 0 won't be removed from the alive array.

Please fix these issues and resubmit.


✨ 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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example


class Carnivore extends Animal {
// write your code here
bite(herb) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This check doesn't verify if herb is an instance of Herbivore. According to the requirements, the bite method should only work on herbivores, not on other carnivores. Add a check for herb instanceof Herbivore.

Comment thread src/herbivoresAndCarnivores.js Outdated
Comment on lines +30 to +33
if (herb.health === 0) {
const i = Animal.alive.indexOf(herb);

Animal.alive.splice(i, 1);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This uses indexOf + splice which violates checklist item #1: 'Try to avoid nesting loops (indexOf + splice), use filter instead'. Use Animal.alive = Animal.alive.filter(animal => animal.health > 0); to remove dead animals.

if (herb.hidden === false) {
herb.health -= 50;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Using === 0 instead of <= 0 means an animal with negative health (e.g., -50) won't be removed from Animal.alive.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Summary

The implementation correctly handles all requirements: Herbivore instances can hide to protect themselves, Carnivore instances can bite herbivores to reduce their health by 50 points, and dead animals (health ≤ 0) are properly removed from the static Animal.alive array using the filter method. The bite method appropriately checks both the instance type and hidden status before dealing damage, preventing carnivores from biting each other or hidden herbivores. All checklist items and task requirements have been satisfied. Great work on the iterative improvements!


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

Footnotes

  1. Rate AI review example

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