Advertisement
kstoyanov

10. Orbit

Sep 18th, 2020
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function orbit(input) {
  2.   const rows = input[0];
  3.   const cols = input[1];
  4.   const starRow = input[2];
  5.   const starCol = input[3];
  6.  
  7.   const matrix = [];
  8.   for (let i = 0; i < rows; i++) {
  9.     matrix.push([]);
  10.   }
  11.  
  12.   for (let row = 0; row < rows; row++) {
  13.     for (let col = 0; col < cols; col++) {
  14.       matrix[row][col] = Math.max(Math.abs(row - starRow), Math.abs(col - starCol)) + 1;
  15.     }
  16.   }
  17.  
  18.   console.log(matrix.map((row) => row.join(' ')).join('\n'));
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement