Matrix Summation
EasyAcc. 98.5%
+15 XP 5
The Grid Total (Matrix)
A Matrix is simply an "array of arrays"—a grid where each element exists at a specific row and column. Summing all elements in a grid is the first step toward mastering complex 2D data processing like image filtering or map analysis.
The Assignment
Your mission is to calculate the global total of the grid. Your function receives a 2D array grid.
- Initialize a
totalvariable to 0. - Use a nested for loop structure:
- The outer loop iterates through the rows.
- The inner loop iterates through the columns of the current row.
- Accumulate every value found at
grid[row][col]. - Print the final
total.
01EXAMPLE 1
Input
grid=[[1, 2], [3, 4]]Output
10Explanation: 1+2+3+4 = 10.
Constraints
- Proper nested loop iteration.
ArraysMatrix
JavaScriptSystem handles I/O — write your function only
Loading...
2 Hidden
Input Arguments
grid[[1,2],[3,4]]
Expected Output
10
Click RUN to test your solution