I have a matrix :
matrix = [[0, 1, 1, 2],
[0, 5, 0, 0],
[2, 0, 3, 3]]
I need to calculate Sum of all array elements which are not under 0 So, in this example Sum should be = 9
I have this function:
function matrixElementsSum(matrix) {
// Write your code here
var Summa =0
for (i = 0; i<4; i++){
var sum =0;
// console.log(matrix[i].length); //4
for(j=0; j<matrix.length; j++){
console.log("Matrix JI "+ matrix[j][i])
sum = sum +matrix[j][i];
if (matrix[j][i-1]!=0){
console.log(matrix[j][i-1])
Summa =Summa+ sum;
}
}
console.log('-----------' +Summa)
console.log("Sum "+sum);
}
return Summa;
}
i think i need to change if (matrix[j-1][i]!=0)
but it doesn't work