Reduce functions can be tricky. My best advice: try log()'ing all your input and intermediary results; the answer usually jumps out to ya.
On Thursday, May 20, 2010, Tom Sante <[email protected]> wrote: > On 20/05/10 23:52, David Goodlad wrote: > > On Thu, May 20, 2010 at 9:38 PM, Tom Sante<[email protected]> wrote: > > Hi, > > I have a reduce function like this: > [snip] > So for some reason if there is only 1 element to be reduced, on the line of > res[v_n]={'mi':v,'ma':v,'c':1,'t':v}; > v becomes v={} and not the actual number. Any ideas why? > > I tested the reduce function with the command line 'js' and send it the > above test keys manually as function argument and then it does result in the > correct return: > "01:00:000074" -> {raw: {mi: -0.213, ma: -0.213, c: 1, t: -0.213}} > "01:00:000084" -> {raw: {mi: -0.213, ma: -0.213, c: 1, t: -0.213}} > > > Sounds like you need to specify group_level; Try playing around in > Futon, you'll see a group_level dropdown. > > Dave > > > Why would I need a group_level parameter? > My key is a simple string "01:00:000074". > Its my values don't get correctly generated by couchjs, since it does out but > proper values in normal commandline js. > > var v = new Number(values[val][v_n]); > if(res.hasOwnProperty(v_n)){ > res[v_n].mi = Math.min(v,res[v_n].mi); > res[v_n].ma = Math.max(v,res[v_n].ma); > res[v_n].c++; > res[v_n].t += v; > }else{ > res[v_n]={'mi':v,'ma':v,'c':1,'t':v}; > } > > It seems that in the above part in the 'else' case the v isn't a number but > an empty object {} >
