Solution - #4534
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am requesting changes because there’s a [CHECKLIST ITEM #1] violation that must be addressed. Functionally, your implementation is solid: Animal has correct defaults, Herbivore.hide and Carnivore.bite behave as specified, and dead animals are removed from Animal.alive. However, on lines 34–38 you remove a dead animal using the indexOf + splice pattern, which the checklist explicitly disallows.
Critical issue to fix:
- Lines 34–38: Replace the
indexOf/spliceremoval with a non-mutatingfilterto rebuildAnimal.alivewithout the dead instance (e.g.,Animal.alive = Animal.alive.filter(a => a !== deadAnimal)). This aligns with the required approach and avoids in-place mutations.
Minor note:
- Keeping operations immutable improves clarity and reduces side effects.
Once you switch to filter for removing dead animals, this will be good to go. Nice work on meeting the functional requirements overall!
✨ 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
|
|
||
| if (animal.health <= 0) { | ||
| const index = Animal.alive.indexOf(animal); | ||
|
|
||
| if (index !== -1) { | ||
| Animal.alive.splice(index, 1); |
There was a problem hiding this comment.
Checklist item #1 violation: This uses indexOf + splice pattern. Prefer using filter instead to create a new array without the dead animal.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Sorry, the pull request review was unsuccessful for the following reasons:
Warning
No changes were made in the pull request since the last review. Please make sure that you have added files to the pull request and committed the changes.
[CODE: NCM]
If the issue is within your control, please address it.
The next review attempt will automatically launch in about 1 hour.
If you believe this is an error or need assistance, please contact the support team.
|
Obrigado pelo feedback! Corrigi a remoção dos animais mortos, substituindo |
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your implementation is approved and meets all requirements. The Animal class correctly implements health (default 100) and name properties, Herbivore properly extends Animal with the hide method that sets hidden to true, and Carnivore's bite method correctly reduces herbivore health by 50 while checking for Herbivore instances and hidden status. The [CHECKLIST #1] requirement to use filter instead of indexOf/splice for removal is satisfied, and [CHECKLIST #2] to set hidden to true (not toggle) is also implemented correctly. All dead animals are properly removed from the static Animal.alive array. Well done!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Gostei bastante desta atividade! Ela me ajudou a entender melhor classes, herança,
extends,super(), métodos estáticos einstanceofna prática. Também foi muito útil para compreender como as classes podem interagir entre si. Obrigado pela aula e pelas explicações!