georgiev955

task 9

Sep 18th, 2023
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function magicMatrices(arrOfarr) {
  2.     let isMagic = true;
  3.     let firstSum = arrOfarr[0].reduce((a, b) => a + b);
  4.     arrOfarr.forEach(row => {
  5.         if (row.reduce((a, b) => a + b) !== firstSum) {
  6.             isMagic = false;
  7.         }
  8.         for (let col = 0; col < row.length; col++) {
  9.             let sum = 0;
  10.             arrOfarr.forEach(row => {
  11.                 sum += row[col];
  12.             })
  13.             if (sum !== firstSum) {
  14.                 isMagic = false;
  15.                 break;
  16.             }
  17.         }
  18.     })
  19.     console.log(isMagic);
  20. }
Advertisement
Add Comment
Please, Sign In to add comment