Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var forestCows = [
  2.   {name: "Legolas", type: "calf", hadCalf: null},
  3.   {name: "Gimli", type: "bull", hadCalf: null},
  4.   {name: "Arwen", type: "cow", hadCalf: null},
  5.   {name: "Galadriel", type: "cow", hadCalf: null},
  6.   {name: "Eowyn", type: "cow", hadCalf: "Legolas"}
  7. ];
  8.  
  9. Object.prototype.noCalvesYet = function () {
  10.   if (this.type == 'cow' && this.hadCalf == null) {
  11.     return true;
  12.   }
  13. };
  14. Array.prototype.countForBreeding = function () {
  15.   var numToBreed = 0;
  16.   for ( var i = 0; i < this.length; i++) {
  17.     if (this[i].noCalvesYet() == true) {
  18.       numToBreed++;
  19.     }
  20.   }
  21.   return numToBreed;
  22. };
  23. console.log('powinny byc 2 nieocielone krowy', forestCows.countForBreeding());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement