Useful reduce functions for CouchDb

Essentially taking some notes for myself..

  • Count:
    function(keys, values, rereduce) {
      var count = 0;
      if(!rereduce)
      {
        count = values.length;
      }
      else
      {
        for(var i in values)
        {
          count += values[i];
        }
      }
      return count;
    }
    
  • Sum:
    function(keys, values, rereduce) {
      var sum = 0;
      for(var i in values)
      {
        sum += values[i];
      }
      return sum;
    }
    
  • Standard deviation: found in the CouchDb source, e.g. std-dev-reduce.js posted: 2009-05-11 07:18
Written on May 11, 2009