Malinov

9. Magic Matrices

Sep 17th, 2021
569
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function magicMatrices(matrix) {
  2.     let allSums = [];
  3.  
  4.     let sumRow = 0;
  5.     let sumCol = 0;
  6.  
  7.     for (let row = 0; row < matrix.length; row++) {
  8.         sumRow = 0;
  9.         sumCol = 0;
  10.         for (let col = 0; col < matrix[row].length; col++) {
  11.             sumRow += matrix[row][col];
  12.             sumCol += matrix[col][row];
  13.         }
  14.         allSums.push(sumRow);
  15.         allSums.push(sumCol);
  16.     }
  17.     let isMagical = allSums.every(s => s === allSums[0]);
  18.    
  19.     return isMagical;
  20. }
RAW Paste Data