Javascript List reducer for CouchDB -


the map out puts key , value, value list of 2 numbers

key1 [1,2] key1 [4,8] key2 [1,6] key2 [2,0] 

the reducer writing reduces

key1 [1+4, 2+8] = key1 [5,10] key2 [1+2, 6+0] = key2 [3,6] 

i wrote script reducer

function (key, values) {      val1 = 0;     val2 = 0;   if(values != null)     for(val in values) {         val1 += parseint(val[0]);          val2 += parseint(val[1]); }  return [val1,val2]; } 

this not seem working , doing wrong here ?

replace val[0] values[val][0]

or better yet:

function (key, values) {      var val1 = 0;     var val2 = 0;     if(values != null) {       for(var = 0; < values.length; i++) {         var val = values[i];         val1 += parseint(val[0]);          val2 += parseint(val[1]);       }     }     return [val1,val2]; } 

it's never idea for...in array because has many other properties.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -