Advertisement
viligen

diagonalAttack

May 24th, 2022
1,019
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function myFunc(arr){
  2.     let sumD1 = 0;
  3.     let sumD2 = 0;
  4.     for (let i = 0; i < arr.length; i++) {
  5.         arr[i] = arr[i].split(' ').map(Number);
  6.        
  7.         sumD1 += arr[i][i]
  8.         sumD2 += arr[i][arr[i].length - 1 -i]
  9.     }
  10.     if (sumD1 === sumD2) {
  11.         for (let i = 0; i < arr.length; i++) {
  12.             for (let j = 0; j < arr.length; j++) {
  13.                 if (i !== j && j !== arr[i].length - 1 - i) {
  14.                     arr[i][j] = sumD1
  15.                 }
  16.             }
  17.         }
  18.        
  19.     }
  20.     for (let i = 0; i < arr.length; i++){
  21.         console.log(arr[i].join(' '));
  22.     }
  23.    
  24. }
Advertisement
RAW Paste Data Copied
Advertisement