-
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
Task solution #3330
base: master
Are you sure you want to change the base?
Task solution #3330
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 implementation! 😊 While your code mostly meets the task requirements, there are a couple of critical issues that need to be addressed before we can approve the pull request:
-
Use of
filter
Method: In theCarnivore
class'sbite
method, you should replace the use ofindexOf
andsplice
with thefilter
method to remove animals with health less than or equal to 0 from theAnimal.alive
array. This change will improve performance and align with the task requirements. -
Type Checking in
bite
Method: Ensure that thebite
method checks if theanimal
is an instance ofHerbivore
and is not hidden. You can useinstanceof Herbivore
to verify the type.
Once these issues are addressed, your code will be in great shape! Keep up the good work, and feel free to reach out if you have any questions or need further assistance. 🚀
✨ 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
} | ||
|
||
class Carnivore extends Animal { | ||
// write your code here | ||
bite(animal) { | ||
if (animal.hidden === false) { |
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 bite
method should check if the animal
is an instance of Herbivore
and not hidden. You can use instanceof Herbivore
to ensure the correct type.
src/herbivoresAndCarnivores.js
Outdated
if (animal.health <= 0 && Animal.alive.includes(animal)) { | ||
Animal.alive.splice(Animal.alive.indexOf(animal), 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.
Instead of manually checking and splicing the Animal.alive
array, consider using the filter
method to remove animals with health less than or equal to 0. This approach is more concise and aligns with the task requirements.
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.
Great job on implementing the Animal
, Herbivore
, and Carnivore
classes! 🎉 Your code aligns well with the task requirements, particularly in the Carnivore
class where the bite
method correctly filters out animals with health less than or equal to 0 and checks for Herbivore
instances. The hide
method in the Herbivore
class is also implemented correctly.
While the code is approved and ready for use, remember to review the comments for any potential improvements. Addressing these will help you enhance your coding skills and avoid similar issues in the future. Keep up the good work and continue learning from each task! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
No description provided.