Question: class AntFarm { / * * * Constructor for the AntFarm class. * * @param { . . . string } ants - Names of
class AntFarm
Constructor for the AntFarm class.
@param string ants Names of the ants.
constructorants
@private
this.ants ants.mapname name, health: ;
Makes the ants in the farm do chores, decreasing their health by points each.
@returns string A message indicating the number of ants starting work.
work
if thisants.length
return No ants here. Did you work them to death?";
this.ants.forEachant
ant.health ;
if anthealth
this.removeAntant;
;
return $thisants.length ants starting work!;
Feeds the ants in the farm, increasing their health by points each.
@param string name The name of the ants to feed.
@returns string A message indicating the success or failure of feeding the ants.
feedname
const antsToFeed this.ants.filterant ant.name name;
if antsToFeedlength
return $name not found!;
antsToFeed.forEachant
ant.health ;
;
return "Yum!";
Removes an ant from the farm.
@param object ant The ant object to remove.
removeAntant
const index this.ants.indexOfant;
if index
this.ants.spliceindex;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
