“Too slow,” Thorne said. “But correct.”
let original = [ [1, 2, 3], [4, 5, 6] ]; let transposed = transposeMatrix(original); console.log(transposed); /* Output: [ [1, 4], [2, 5], [3, 6] ] */ Codehs 8.1.5 Manipulating 2d Arrays
A 2D array, also known as a matrix, is a data structure that consists of rows and columns of elements. Each element is identified by its row and column index. In CodeHS, 2D arrays are used to represent grids, images, and other types of data that require multiple dimensions. “Too slow,” Thorne said
To change a value, you access it directly via its coordinates [row][col] and assign a new value. For example, to double every value in a grid: matrix[row][col] = matrix[row][col] * 2; Use code with caution. Step-by-Step CodeHS Exercise Walkthrough In CodeHS, 2D arrays are used to represent
Create your nested for loops to traverse the grid.