title: Calculate average from json data based on multiple filters
body: <p>I've a json array as given below. </p>
  
  <pre><code>var dataObject=[ 
  { "SupplierName" : "John", "Category " : "A", "Points" : 3 },
  { "SupplierName" : "John", "Category " : "A", "Points" : 11 },
  { "SupplierName" : "John", "Category " : "A", "Points" :  },
  { "SupplierName" : "John", "Category " : "B", "Points" : 2 },
  { "SupplierName" : "John", "Category " : "B", "Points" : 6 },
  { "SupplierName" : "Praveen", "Category " : "A", "Points" : 3 },
  { "SupplierName" : "Praveen", "Category " : "A", "Points" : 7 } 
  ];
  </code></pre>
  
  <p>I would like to find average of Points and create json in below format. If Points is blank for any SupplierName then it should be excluded from average calculation.</p>
  
  <pre><code>var result=[ 
  { "SupplierName" : "John", "Category " : "A",  "Points" : 14, "Average" : 7 },
  { "SupplierName" : "John", "Category " : "B", "Points" : 8, "Average" : 4 },
  { "SupplierName" : "Praveen", "Category " : "A", "Points" : 10, "Average" : 5 } 
  ];
  </code></pre>
  
  <p>I tried below code but it is filtering based on SupplierName. I am not sure how to filter based on multiple values. Appreciate if you can guide me on this.</p>
  
  <pre><code>var count=0;
  var avg=0;
  var result = dataObject.reduce(function(res, obj) {
      if (!(obj.SupplierName in res)){
              count=0;
          avg=0;
          res.__array.push(res[obj.SupplierName] = obj);
          count++;
          }
      else {
          res[obj.SupplierName].Points += obj.Points;        
          count++;
          res[obj.SupplierName].Points =res[obj.SupplierName].Points;
          avg=res[obj.SupplierName].Points/count;     
          res[obj.SupplierName].Average =avg;
      }
      return res;
  }, {__array:[]}).__array
              .sort(function(a,b) { return b.SupplierName - a.SupplierName; });
  alert(JSON.stringify(result));
  </code></pre>