Insights Blog
-- Browse All Articles --
Physics Articles
Physics Tutorials
Physics Guides
Physics FAQ
Math Articles
Math Tutorials
Math Guides
Math FAQ
Education Articles
Education Guides
Bio/Chem Articles
Technology Guides
Computer Science Tutorials
Forums
Chemistry
Biology and Medical
Earth Sciences
Computer Science
Computing and Technology
DIY Projects
Trending
Featured Threads
Log in
Register
What's new
Search
Search
Search titles only
By:
Chemistry
Biology and Medical
Earth Sciences
Computer Science
Computing and Technology
DIY Projects
Menu
Log in
Register
Navigation
More options
Contact us
Close Menu
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Forums
Other Sciences
Programming and Computer Science
Need of transposed[i] = []; when we already have var transposed = []
Reply to thread
Message
[QUOTE="shivajikobardan, post: 6846633, member: 695701"] [B]TL;DR Summary:[/B] codewars kata confusion What's the need of the commented code here? [CODE=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]]) [/CODE] When that part is commented, it throws an error: [B]Uncaught TypeError: Cannot set properties of undefined (setting '0')[/B] I'm trying to understand the need of it. Because we've already initialized var transposed = [], [/QUOTE]
Insert quotes…
Post reply
Forums
Other Sciences
Programming and Computer Science
Need of transposed[i] = []; when we already have var transposed = []
Back
Top