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.

  1. Initialize a total variable to 0.
  2. Use a nested for loop structure:
    • The outer loop iterates through the rows.
    • The inner loop iterates through the columns of the current row.
  3. Accumulate every value found at grid[row][col].
  4. Print the final total.

01EXAMPLE 1

Inputgrid=[[1, 2], [3, 4]]
Output10

Explanation: 1+2+3+4 = 10.

Constraints

  • Proper nested loop iteration.
ArraysMatrix
JavaScript
Loading...
2 Hidden

Input Arguments

grid[[1,2],[3,4]]

Expected Output

10

Click RUN to test your solution