Nodejs Array Count Predicate countWhere(xAndY)

Here you can find the source of countWhere(xAndY)

Method Source Code

//Counts amount of items in array that follow a particular pattern.
//call like this:
//myArray.countWhere(function(item)){return item.x is something && item.y is something;}
//// w ww.j  a  v a 2  s  .c o m
Array.prototype.countWhere = function(xAndY){
   var count = 0;
   for(var i = 0; i < this.length; i++)
   {
      if(xAndY(this[i])){
         count++;
      }
   }
   return count;
}

Related

  1. countWhere(xAndY)
    Array.prototype.countWhere = function(xAndY){
      var count = 0;
      for(var i = 0; i < this.length; i++)
        if(xAndY(this[i])){
          count++;
      return count;
    ...