-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
add herbivores and carnivores #3331
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your hard work on this task! 😊 There are a couple of critical issues that need to be addressed to meet the core requirements. The hide
method in the Herbivore
class should set the hidden
property to true
instead of toggling it. Additionally, the die
method should use the filter
method instead of splice
for better performance and to align with the checklist requirements. Please make these changes, and your solution will be ready for approval! Keep up the great work! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review
button in the Reviewers tab.
src/herbivoresAndCarnivores.js
Outdated
} | ||
|
||
hide() { | ||
this.hidden = !this.hidden; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hide
method toggles the hidden
property, but according to the additional prompt rules, it should simply set this.hidden
to true. Consider changing this implementation.
src/herbivoresAndCarnivores.js
Outdated
const index = Animal.alive.indexOf(this); | ||
|
||
if (index !== -1) { | ||
Animal.alive.splice(index, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The die
method uses splice
to remove the animal from the Animal.alive
array. According to the checklist, it is preferred to filter animals with health less than or equal to 0 using the filter
method. Consider refactoring this logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Summary
Great job on implementing the task requirements! 🎉 Your code is mostly correct and aligns well with the specified constraints. Here are some highlights and areas for improvement:
-
Animal Class: You've successfully implemented the
Animal
class withhealth
andname
properties, and a staticalive
array to track living animals. This is a solid foundation for your animal hierarchy. -
Herbivore Class: The
Herbivore
class correctly extendsAnimal
and implements thehide
method, setting thehidden
property totrue
. This functionality is crucial for the herbivore's survival mechanism. -
Carnivore Class: The
Carnivore
class extendsAnimal
and thebite
method is implemented correctly. It checks if the target is an instance ofHerbivore
, is not hidden, and is alive before reducing its health. This ensures that the carnivore's actions are logical and effective. -
Use of Filter Method: The
die
method efficiently uses thefilter
method to remove dead animals from theAnimal.alive
array, which is both efficient and meets the performance guidelines.
There are no critical issues found, and your code is ready to proceed. However, always ensure to review any comments for potential improvements and learning opportunities. Keep up the great work and continue refining your skills! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
No description provided.