Advertisement
Guest User

Untitled

a guest
Oct 5th, 2018
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  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