There are few problems here. One is the starting index for j. It should be 0. Second, the code in the loop itself. For every item, you should be checking item above it and not the one below. Once i = length,
i + 1
will result in error. Also, the limit value in second for loop may or may not be same as first one. You basically have an array of arrays. A bit more general solutions could be something like this:
function F(x){
var sum = 0;
for(var i = 0; i < x.length; i++){
for(var j = 0; j < x[i].length; j++){
if(i>0){
if(x[i-1][j] > 0){
sum += x[i][j];
}
}
else{
sum += x[i][j];
}
}
}
return sum;
}
This still assumes that all sub-arrays have same number of elements. If there are differences in them too, you will need to check for length of previous array.