Codehs 8.1.5 Manipulating 2d Arrays -
Writing grid[r][c] + 5; does nothing. You must assign it: grid[r][c] = grid[r][c] + 5; (or grid[r][c] += 5; ). If you want to debug your specific code, tell me:
Avoid generic variables. Use row and col instead of i and j to drastically reduce typos.
, and I'll write the complete code solution for you.
result.push(newRow);
matrix[0].length returns the total number of columns in the first row. Codehs 8.1.5 Manipulating 2d Arrays
The value is calculated by adding the first element of the first array ( array[0][0] ) and the second-to-last element of the current array ( array[2][array[2].length - 2] ) or similar based on specific prompt variations. // Row 1: Set last element to length of this sub-array updateValue(array, ].length - ].length); // Row 2: Set last element to total 2D length updateValue(array, ].length - , length2D); // Row 3: Set last element based on sum requirements updateValue(array, ].length - ] + array[ ][array.length - Use code with caution. Copied to clipboard 3. Defining the updateValue Method This method should directly access the array at the given and assign the new updateValue( value) arr[row][col] = value; Use code with caution. Copied to clipboard Summary of Result The core objective is to practice row-major indexing array[row][column]
Thus the article will include:
return result;
function doubleArray(matrix) for (let i = 0; i < matrix.length; i++) for (let j = 0; j < matrix[i].length; j++) matrix[i][j] *= 2; Writing grid[r][c] + 5; does nothing
Ensure you are accessing the correct variable. In CodeHS, you are often given an existing grid. 2. Set Up the Nested Loops
I don't have direct access to CodeHS's specific problem statements or answer keys, but I can certainly help you understand (since CodeHS Unit 8.1 is typically Java's 2D arrays).
public static void manipulateArray(int[][] grid) // Code goes here Use code with caution. Step 2: Traverse the Grid Set up your boundaries using .length .
var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]; for (var i = 0; i < array.length; i++) array[i].splice(1, 1); // remove column at index 1 Use row and col instead of i and
If your code is failing the autograder tests, write a quick helper function using System.out.print(grid[r][c] + " ") to print the grid to the console. Visualizing the matrix makes tracking logic errors much easier.
This algorithm searches the entire grid to count how many times a target value appears.
return matrix;









