Codehs 8.1.5 Manipulating 2d Arrays -

Aggregating data is a common requirement. Here's how to sum all numbers in a 2D array:

A 2D array is essentially an .

var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]; array.push([10, 11, 12]); // add new row console.log(array); // output: [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]] Codehs 8.1.5 Manipulating 2d Arrays

for(int row = 0; row < grid.length; row++) for(int col = 0; col < grid[row].length; col++) System.out.print(grid[row][col] + " "); System.out.println(); // Moves to next line after each row Use code with caution. Tips for Success on CodeHS

return result;

Whether you need help or building a specific algorithm ? Share public link

Finding a specific score, detecting if a student scored a perfect 100, or counting students who passed. Aggregating data is a common requirement

Sometimes you only want to alter one section of the grid rather than the whole thing.

function transposeMatrix(matrix) return matrix[0].map((_, colIndex) => matrix.map(row => row[colIndex])); Share public link Finding a specific score, detecting

Manipulating 2D arrays is used in:

About The Author

Jacob Sahms

Jacob serves as a United Methodist pastor in Virginia, where he spends his downtime in a theater or playing sports

Leave a reply

Your email address will not be published. Required fields are marked *