Malinov

Untitled

Sep 17th, 2021
935
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.length; col++) {
  11.             sumRow += matrix[row][col];
  12.             sumCol += matrix[col][row];
  13.         }
  14.         allSums.push(sumRow);
  15.         allSums.push(sumCol);
  16.     }
  17.  
  18.     let isMagical = sums => sums.every(v => v === sums[0]);
  19.  
  20.     return isMagical(allSums);
  21. }
RAW Paste Data