I am looking to create a function that takes two arguments, rows and columns. The goal of this function is to generate a 2D array with the specified numbers and rows provided as input. Below is the code snippet for implementing this:
Feedback from seasoned developers would be greatly appreciated as I am still learning.
Despite scouring StackOverflow, performing Google searches, and reviewing various websites, I have been unable to find a solution.
function generate2DArray(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;
}