I need to write a function which takes two arguments - rows and columns. The purpose of this function is returning 2d array with given numbers and rows. I need to return the array by using the function. Here's a code:
I'm a beginner and every feedback will be strongly appreciated. :-)
I've checked StackOverflow, I've tried to google it, check appropriate websites - unfortunately, no luck
function create2Darray(A) {
var columns = [];
var rows = Math.sqrt(A.length);
for (var i = 0; i < rows; i++) {
columns[i] = [];
for (var j = 0; j < rows; j++) {
columns[i][j] = A[i * rows + j];
}
}
return columns;
}
columns[i].push(A[i * rows + j])