nikolayneykov

Untitled

Feb 10th, 2019
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function isMagicMatrix(matrix) {
  2.     let sum = matrix[0].reduce((a, b) => a + b);
  3.     let result = true;
  4.  
  5.     for (let i = 0; i < matrix.length; i++) {
  6.         let horizontalSum = matrix[i].reduce((a, b) => a + b, 0);
  7.         let verticalSum = matrix.map((row) => row[i]).reduce((a, b) => a + b, 0);
  8.         if (sum !== horizontalSum || sum !== verticalSum) {
  9.             result = false;
  10.             break;
  11.         }
  12.     }
  13.     console.log(result);
  14. }
Advertisement
Add Comment
Please, Sign In to add comment