8.1.5 Manipulating 2d Arrays _top_: Codehs
We'll write an article titled something like "Mastering CodeHS 8.1.5: Manipulating 2D Arrays – A Complete Guide". The article will cover:
The 8.1.5 exercise usually asks you to take a provided 2D array—often representing a grid of numbers—and manipulate it in some way. Common tasks include: Adding a specific value to every element. Multiplying every element by a factor.
console.log(array); // output: [[1, 2, 3, 10], [4, 5, 6, 10], [7, 8, 9, 10]] Codehs 8.1.5 Manipulating 2d Arrays
function sumBorder(matrix) let sum = 0; let rows = matrix.length; let cols = matrix[0].length;
For example:
// Print result (using Arrays.deepToString for clarity) System.out.println(java.util.Arrays.deepToString(result));
Use the assignment operator ( = ) to update the element at [row][col] . We'll write an article titled something like "Mastering
function zeroOutNegatives(matrix) for (let i = 0; i < matrix.length; i++) for (let j = 0; j < matrix[i].length; j++) if (matrix[i][j] < 0) matrix[i][j] = 0;