Nodejs Array Count countCattle(cattle)

Here you can find the source of countCattle(cattle)

Method Source Code

// After/*from  www.  ja v a  2 s. co  m*/

Array.prototype.countCattle = function(cattle){
  var number = 0;
  for(var i = 0; i < this.length; i ++){
    if(this[i].type == cattle){
      number ++ ;
    }
  }
  return number;
};

Related

  1. count(filter)
    Array.prototype.count = function(filter)
      var ct = 0;
      for (var i = 0; i< this.length; i++) {
        if(filter(this[i])){
          ct++;
      return ct;
    ...
    
  2. count(n)
    Array.prototype.count = function(n) {
      var count = 0;
      for (var i = 0; i < this.length; i++) {
        if (this[i] == n) count++;
      return count;
    function primeFactors(n) {
      var f = [];
    ...
    
  3. count(value)
    Array.prototype.count = function (value) {
      var count = 0, i;
      for (i = 0; i < this.length; ++i) {
        if (this[i] === value) {
          ++count;
      return count;
    };
    ...
    
  4. count(value)
    Array.prototype.count = function (value) {
      var count = 0, i;
      for (i = 0; i < this.length; ++i) {
        if (this[i] === value) {
          ++count;
      return count;
    };
    ...
    
  5. countCattle( kind )
    Array.prototype.countCattle = function ( kind ){
      var numKind = 0;
      for(var i = 0; i<this.length; i++){
        if(this[i].type == kind){
          numKind++;
      return numKind;
    };
    ...
    
  6. countCattle(kind)
    Array.prototype.countCattle = function(kind) {
      var numKind = 0;
      for (var i = 0; i<this.length; i++) {
        if (this.type == kind){
          numKind++;
      return numKind;
    };
    ...
    
  7. countCattle(kind)
    Array.prototype.countCattle = function(kind) {
      var numKind = 0;
      for (var i = 0; i < this.length; i++) {
        if (this[i].type == kind) {
          numKind++;
      return numKind;
    };
    ...
    
  8. countCattle(kind)
    Array.prototype.countCattle = function (kind) {
      var numKind = 0;
      for (var i = 0; i < this.length; i++) {
        if (this[i].type == kind) {
          numKind++
      return numKind
    var canyonCows = [
      { name: "Bessie", type: 'cow', hadCalf: 'Burt'},
      { name: "Bessie", type: 'bull', hadCalf: 'Burt'},
      { name: "Bessie", type: 'cow', hadCalf: 'Burt'},
      { name: "Bessie", type: 'cow', hadCalf: 'Burt'},
      { name: "Bessie", type: 'calf', hadCalf: null},
    ]
    console.log(canyonCows.countCattle('cow'))
    
  9. countCattle(kind)
    Array.prototype.countCattle = function(kind) {
      var numKind = 0;
      for (i in this) {
        if (this[i]["type"] == kind) numKind++;
      return numKind;
    };