couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Patrick Antivackis <patrick.antivac...@gmail.com>
Subject Re: A reduce with multiple totals
Date Sat, 16 May 2009 09:46:46 GMT
Hello Oliver,
You are mistaking on the way to iterate over the values object.
You should do like this :


function(keys, values) {
  var totalcallsfor = 0;
  var totalanswered = 0;
values.forEach(function(value) {
    totalcallsfor = totalcallsfor + value.callfor;
    totalanswered = totalanswered + value.answered;
});
  return {'callfor': totalcallsfor, 'answered':totalanswered};
}

Regards


2009/5/16 Oliver Boermans <boermans@gmail.com>

> Hi CouchCrew.
>
> Hoping you guys can help me with my first reduce composition problem.
>
> My app is intended to log phone calls. Now I want to output some
> tallies. For each logged call I am emitting two items: one each for
> the call answered and the call’s intended recipient. I want a tally of
> calls answered and calls for with the phone answerer/recipient as the
> key.
>
> Please take a look at the code here:
> http://www.friendpaste.com/64pGMIf7OoAOkSvRew8AOB
>
> The results are null instead of my intended total. What am I doing
> wrong in my reduce function?
>
> My approach feels good up until reduce. Please correct me if there is
> a better angle to this problem.
>
> I’m spoilt by Firebug as a tool for troubleshooting this kind of code
> in a browser. I’d be very interested to hear what approach you might
> use to nut out what is going wrong when composing something like this
> in Futon.
>
> Many thanks
> Ollie
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message