Skip to content

Commit bdb05cf

Browse files
committed
fixed with filter method
1 parent 39bf1da commit bdb05cf

1 file changed

Lines changed: 2 additions & 6 deletions

File tree

src/herbivoresAndCarnivores.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,9 @@ class Carnivore extends Animal {
3030

3131
target.health -= 50;
3232

33-
if (target.health <= 0) {
34-
const indexOfDead = Animal.alive.indexOf(target);
33+
const deadAnimals = Animal.alive.filter((animal) => animal.health > 0);
3534

36-
if (indexOfDead !== -1) {
37-
Animal.alive.splice(indexOfDead, 1);
38-
}
39-
}
35+
Animal.alive = deadAnimals;
4036
}
4137
}
4238

0 commit comments

Comments
 (0)