Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2019
554
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(arr) {
  2.   function calcSum(a, b) {
  3.     return a + b;
  4.   }
  5.  
  6.   let sumOfRowOne = arr[0].reduce(calcSum);
  7.   let sumOfRowLast = arr[arr.length-1].reduce(calcSum);
  8.  
  9.   if (sumOfRowOne == sumOfRowLast) {
  10.     let sumOfLeftCol = 0;
  11.     let sumOfRightCol = 0;
  12.     for (let i = 0; i < arr.length; i++) {
  13.       sumOfLeftCol += arr[i][0];
  14.       sumOfRightCol += arr[i][arr.length-1];
  15.      
  16.     }
  17.     return sumOfLeftCol == sumOfRightCol &&  sumOfRightCol == sumOfRowOne ?
  18.       true : false
  19.  
  20. } else {
  21.     return false;
  22.   }
  23. }
Advertisement
RAW Paste Data Copied
Advertisement