Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function orbit(input) {
- let rows = input[0];
- let cols = input[1];
- let starRow = input[2];
- let starCol = input[3];
- let matrix = [];
- for(let i=0; i<rows; i++) {
- matrix.push([]);
- }
- for(let row = 0; row< rows; row++) {
- for(let col=0; col<cols; col++) {
- let el = Math.max(Math.abs(row - starRow), Math.abs(col - starCol)) + 1;
- matrix[row][col]=el;
- }
- }
- console.log(matrix.map(row => row.join(" ")).join("\n"));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement