Nodejs Array Count countOf(pValue)

Here you can find the source of countOf(pValue)

Method Source Code

Array.prototype.countOf = function (pValue){
    var count   = 0;
    var lArray  = this || [];
    var lLength = lArray.length
    /*from w ww. jav a 2 s  .c  o  m*/
    for (var i = 0 ; i < lLength; i++){
        if (lArray[i] == pValue){
            count++;
        }
    }
    
    return count;
}

Related

  1. 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'))
    
  2. countCattle(kind)
    Array.prototype.countCattle = function(kind) {
      var numKind = 0;
      for (i in this) {
        if (this[i]["type"] == kind) numKind++;
      return numKind;
    };
    
  3. calculateCount()
    Array.prototype.calculateCount = function() {
        return this.length;
    };
    var a = ["1", "2"];
    var count = a.calculateCount();
    console.log(count);
    
  4. countForBreeding()
    Array.prototype.countForBreeding = function() {
      var numToBreed = 0;
      for (var i = 0; i < this.length; i++) {
        if (this[i].noCalvesYet()) {
          numToBreed++;
      return numToBreed;
    };
    ...
    
  5. countItem(item)
    Array.prototype.countItem = function (item) {
            return this.filter(function (i) {
                return i === item
            }).length;
    };
    
  6. countType(type)
    Array.prototype.countType = function (type) {
      var count = 0
      for( var i = 0, x = this.length; i < x; i++) {
        if (this[i] === type) {
          count++
      return count
    
  7. element_count()
    Array.prototype.element_count = function(){
      var count = 0;
      for(var i=0; i<this.length; i++){
        if(this[i] != undefined){
          count++;
      return count;
    
  8. first_n(count)
    Array.prototype.first_n=function(count) {
      var a=[];
      for(var i=0;i<count;i++) {
        a.append(this[i]);
      return a;
    
  9. valueCount(value)
    Array.prototype.valueCount = function (value) {
      var count = 0;
      for( var i = 0; i < this.length; i++) {
        if ( this[i] === value) {
          count++;
        };
      };
      return count;
    };
    ...