- #1
shivajikobardan
- 674
- 54
- TL;DR Summary
- codewars kata confusion
What's the need of the commented code here?
When that part is commented, it throws an error:
Uncaught TypeError: Cannot set properties of undefined (setting '0')
I'm trying to understand the need of it. Because we've already initialized
var transposed = [],
JavaScript:
function transpose(matrix) {
var transposed = [],
rows = matrix.length,
cols = matrix[0].length;
for (i = 0; i < cols; i++) {
// transposed[i] = [];
for (var j = 0; j < rows; j++) {
transposed[i][j] = matrix[j][i];
}
}
console.log(transposed);
}
transpose([[1, 2, 3], [4, 5, 6]])
When that part is commented, it throws an error:
Uncaught TypeError: Cannot set properties of undefined (setting '0')
I'm trying to understand the need of it. Because we've already initialized
var transposed = [],
Last edited by a moderator: