Prototypes I

The cowboy-devs at the Plains of Prototypes seek your assistance. They’ve got a big herd-merger to manage, and they have multiple lists of cattle being imported from multiple regions. Each individual bovine is represented as a JavaScript object, and multiple bovine objects are contained together as an unordered list within an array. Here’s an example, which happens to be the list that came over from good old Conditional Canyon:

var canyonCows = [
  {name: "Bessie", type: "cow", hadCalf: "Burt"},
  {name: "Donald", type: "bull", hadCalf: null},
  {name: "Esther", type: "calf", hadCalf: null},
  {name: "Burt", type: "calf", hadCalf: null},
  {name: "Sarah", type: "cow", hadCalf: "Esther"},
  {name: "Samson", type: "bull", hadCalf: null},
  {name: "Delilah", type: "cow", hadCalf: null}
];
The only problem is that the cowboy-devs don’t have time to go through the dozens of lists they are getting and count each specific type of cattle being imported, i.e. the number of cows, bulls, or a calfs. Since the only use the cowboys have for arrays is to make these lists of cattle objects, they’ve asked you to go ahead and add a function, called countCattle, to the Array prototype that will allow any array list of Cows to access precisely how many bulls, cows, or calfs are present in the array. The function should accept a parameter and return a number value.
Prototypes III

To let current mother cows rest, the cowboy-devs at the Plains of Prototypes have decided only to breed those cows that have not given birth to any calves yet. Since the only use the cowboy-devs have for the JavaScript object is in making cattle representations (it’s a rough life), they want to go ahead and add some functionality to the Object prototype itself. They’ve asked you to build two functions in order, explained here:

A function called noCalvesYet, which will be added to the Object prototype, and will return true for an object if the object is a cow with no calves…and false otherwise.

A function called countForBreeding, which will be added to the Array prototype, and will examine an array’s list of cattle objects, counting all cows that are not moms. To do this, you should employ the function in criteria number (1), as well as use a counter variable called numToBreed. Ultimately, this function should return numToBreed representing precisely how many non-mother cows are available within any array.

A list of cattle is provided below for your reference:

var forestCows = [
  {name: "Legolas", type: "calf", hadCalf: null},
  {name: "Gimli", type: "bull", hadCalf: null},
  {name: "Arwen", type: "cow", hadCalf: null},
  {name: "Galadriel", type: "cow", hadCalf: null},
  {name: "Eowyn", type: "cow", hadCalf: "Legolas"}
];
Prototypes IV

Welp, it’s time to figure out which cows are in line for a first breeding. Your awesome prototype skills are making life easy on the cowboy-devs, so easy that they’ve asked you to use your own new functions to find out how many cows haven’t had calves yet out of the lists you’ll find below. Calculate this amount and store it in a variable called numPriorityCows. Alert the following message to the screen:

Herd-merger has indicated <number> cows of top breeding priority.
Your previously built prototypal functions are provided for your reference.

var canyonCows = [
  {name: "Bessie", type: "cow", hadCalf: "Burt"},
  {name: "Donald", type: "bull", hadCalf: null},
  {name: "Esther", type: "calf", hadCalf: null},
  {name: "Burt", type: "calf", hadCalf: null},
  {name: "Sarah", type: "cow", hadCalf: "Esther"},
  {name: "Samson", type: "bull", hadCalf: null},
  {name: "Delilah", type: "cow", hadCalf: null}
];

var valleyCows = [
  {name: "Danielle", type: "cow", hadCalf: null},
  {name: "Brittany", type: "cow", hadCalf: "Christina"},
  {name: "Jordan", type: "bull", hadCalf: null},
  {name: "Trevor", type: "bull", hadCalf: null},
  {name: "Christina", type: "calf", hadCalf: null},
  {name: "Lucas", type: "bull", hadCalf: null}
];

var forestCows = [
  {name: "Legolas", type: "calf", hadCalf: null},
  {name: "Gimli", type: "bull", hadCalf: null},
  {name: "Arwen", type: "cow", hadCalf: null},
  {name: "Galadriel", type: "cow", hadCalf: null},
  {name: "Eowyn", type: "cow", hadCalf: "Legolas"}
];

var badlandsCows = [
  {name: "Voldemort", type: "bull", hadCalf: null},
  {name: "Maleficent", type: "cow", hadCalf: null},
  {name: "Ursula", type: "cow", hadCalf: "Draco"},
  {name: "Draco", type: "calf", hadCalf: null},
  {name: "Joker", type: "bull", hadCalf: null},
  {name: "Chucky", type: "calf", hadCalf: null},
  {name: "Samara", type: "cow", hadCalf: "Chucky"}
];