John_IV

07MagicMatrices

May 27th, 2020
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(ar) {
  2.     function sum(c) {
  3.         return typeof c === 'number' ? ar.reduce((sum, ar) => sum + ar[c], 0) : c.reduce((sum, e) => sum + e, 0);
  4.     }
  5.  
  6.     for (let i = 0; i < ar.length - 1; i++)
  7.         if (sum(ar[i]) !== sum(ar[i + 1]) || sum(i) !== sum(i + 1))
  8.             return false;
  9.  
  10.     return true;
  11. }
Advertisement
Add Comment
Please, Sign In to add comment