Advertisement
Aliendreamer

matrix orbit

Jan 29th, 2019
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function orbit(input) {    
  2.     let rows = input[0];
  3.     let cols = input[1];
  4.     let starRow = input[2];
  5.     let starCol = input[3];
  6.  
  7.     let 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.             let el = Math.max(Math.abs(row - starRow), Math.abs(col - starCol)) + 1;
  15.             matrix[row][col]=el;
  16.         }
  17.     }
  18.  
  19.     console.log(matrix.map(row => row.join(" ")).join("\n"));
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement