Javascript Array countCattle(kind)

Description

Javascript Array countCattle(kind)


Array.prototype.countCattle = function(kind) {
  var numKind = 0;
  for (var i = 0; i<this.length; i++) {
    if (this.type == kind){
      numKind++;/*from   www .  ja  va2 s  . c  o  m*/
    }
  }
  return numKind;
};

Javascript Array countCattle(kind)

Array.prototype.countCattle = function(kind) {
  var numKind = 0;
  for (var i = 0; i < this.length; i++) {
    if (this[i].type == kind) {
      numKind++;//from   w w w.  j a  v  a  2s  . c  om
    }
  }
  return numKind;
};

alert(canyonCows.countCattle("calf") + valleyCows.countCattle("bull") + forestCows.countCattle("cow"));



PreviousNext

Related