Hey guys I need soe help please :P
What's wrong with this code?
var arr = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
var narr = []; // want to be like that [[1, 4, 7], [2, 5, 8], [3, 6, 9]]
function arange(mass) {
for (var i = 0; i < mass.length; i++) {
for (var j = 0; j < mass[i].length; j++) {
narr[mass[i]].push(mass[j][i]);
}
}
}
If i call the function there is a problem : "TypeError: Cannot read property 'push' of undefined." Thank you. Also link here
narr[mass[i]]is undefined.narr.push(mass[j][i]);will give[1,4,7,2,5,8,3,6,9]so you'll need to think about how to create another level of array within the array to encapsulate each inner set