didkoslawow

Untitled

Jan 29th, 2023
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function spiralMatrix(rows, columns) {
  2.     const spiralMatrix = [];
  3.  
  4.     for (let i = 0; i < rows; i++) {
  5.         spiralMatrix.push([]);
  6.     }
  7.  
  8.     let counter = 1;
  9.  
  10.     let startRow = 0;
  11.     let endRow = rows - 1;
  12.     let startColumn = 0;
  13.     let endColumn = columns - 1;
  14.  
  15.     while (startColumn <= endColumn && startRow <= endRow) {
  16.         for (let i = startColumn; i <= endColumn; i++) {
  17.             spiralMatrix[startRow][i] = counter;
  18.             counter++;
  19.  
Advertisement
Add Comment
Please, Sign In to add comment