couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Candler <B.Cand...@pobox.com>
Subject Re: Reduce limitations
Date Sat, 25 Apr 2009 22:19:48 GMT
On Sat, Apr 25, 2009 at 10:39:12PM +0100, Brian Candler wrote:
> I am considering using a reduce function for a low-ordinality value

Of course I meant low cardinality.

FWIW, here's a working implementation:

function(ks, vs, co) {
  if (co) {
    var result = vs.shift();
    for (var i in vs) {
      for (var j in vs[i]) {
        result[j] = (result[j] || 0) + vs[i][j];
      }
    }
    return result;
  } else {
    var result = {};
    for (var i in ks) {
      var key = ks[i];
      result[key[0]] = (result[key[0]] || 0) + 1;
    }
    return result;
  }
}

Regards,

Brian.

Mime
View raw message