Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function spiralMatrix(rows, columns) {
- const spiralMatrix = [];
- for (let i = 0; i < rows; i++) {
- spiralMatrix.push([]);
- }
- let counter = 1;
- let startRow = 0;
- let endRow = rows - 1;
- let startColumn = 0;
- let endColumn = columns - 1;
- while (startColumn <= endColumn && startRow <= endRow) {
- for (let i = startColumn; i <= endColumn; i++) {
- spiralMatrix[startRow][i] = counter;
- counter++;
Advertisement
Add Comment
Please, Sign In to add comment