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