Advertisement
megi_al

magicMatrices

May 27th, 2021
849
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function magicMatrices(matrix) {
  2.     for (let i = 0; i < matrix.length - 1; i++) {
  3.         let sumROne = matrix[i].reduce((a, b) => a + b, 0);
  4.         let sumRTwo = matrix[i + 1].reduce((a, b) => a + b, 0);
  5.         let sumCOne = 0;
  6.         let sumCTwo = 0;
  7.  
  8.         for (let j = 0; j < matrix.length; j++) {
  9.             sumCOne += matrix[i][j];
  10.             sumCTwo += matrix[i + 1][j];
  11.         }
  12.  
  13.         if (sumROne !== sumRTwo || sumCOne !== sumCTwo) {
  14.             return false;
  15.         }
  16.     }
  17.  
  18.     return true;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement