Skip to content
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

Solution #1808

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Solution #1808

wants to merge 4 commits into from

Conversation

PanyaPrimal
Copy link

No description provided.

Copy link

@33Orange 33Orange left a comment

Choose a reason for hiding this comment

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

Good job.

A few moments

@@ -1,15 +1,46 @@
'use strict';

class Animal {
// write your code here
static alive = [];

Choose a reason for hiding this comment

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

Suggested change
static alive = [];

if (index !== -1) {
Animal.alive.splice(index, 1);
}
}
}

Choose a reason for hiding this comment

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

#952
That's why you have failed tests

Suggested change
Animal.alive = [];

Comment on lines 12 to 17
static removeFromAlive(animal) {
const index = Animal.alive.indexOf(animal);
if (index !== -1) {
Animal.alive.splice(index, 1);
}
}

Choose a reason for hiding this comment

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

You can use only 1 filter instead, which will clear the array from animals with health less than or equal to 0

}

bite(animal) {
if (!(animal instanceof Carnivore) && !animal.hidden) {

Choose a reason for hiding this comment

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

Just check if animal instanceof Herbivore instead.

Suggested change
if (!(animal instanceof Carnivore) && !animal.hidden) {
if (animal instanceof Herbivore && !animal.hidden) {

Comment on lines 10 to 12
static removeFromAlive(animal) {
Animal.alive = Animal.alive.filter((a) => a.health > 0);
}
Copy link

Choose a reason for hiding this comment

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

so where do you use animal here?

Comment on lines 5 to 7
this.name = name;
this.health = health;
Animal.alive.push(this);
Copy link

Choose a reason for hiding this comment

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

Suggested change
this.name = name;
this.health = health;
Animal.alive.push(this);
this.name = name;
this.health = health;
Animal.alive.push(this);

Animal.alive.push(this);
}

static removeFromAlive() {
Copy link

Choose a reason for hiding this comment

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

Suggested change
static removeFromAlive() {
static filterDeadAnimals() {

animal.health -= 50;

if (animal.health <= 0) {
Animal.removeFromAlive(animal);
Copy link

Choose a reason for hiding this comment

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

This function doesn't take any parameters

Comment on lines +31 to +36
if (animal instanceof Herbivore && !animal.hidden) {
animal.health -= 50;

if (animal.health <= 0) {
Animal.filterDeadAnimals();
}

Choose a reason for hiding this comment

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

you should avoid nested if statements - as it makes your code more difficult to read

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.

4 participants