The map out puts a key and value, value is a list of two numbers
key1 [1,2]
key1 [4,8]
key2 [1,6]
key2 [2,0]
The reducer i was writing reduces to
key1 [1+4, 2+8] = key1 [5,10]
key2 [1+2, 6+0] = key2 [3,6]
I wrote this script for 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 does not seem to be working , Am I doing something wrong here ?
Replace
val[0]withvalues[val][0]or better yet:
It’s never a good idea to for…in an Array because it has some many other properties.