dabidabidesh

7-разгеле=>100

Sep 23rd, 2020
300
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(arr) {
  2.   let sums = [];
  3.  
  4.   /* arr.forEach(row => {
  5.     let sum = row.reduce((a, b) => a + b, 0);
  6.     sums.push(sum);
  7.   }); */
  8.   let lengthArr = arr.length
  9.   let arrSum = 0
  10.  
  11.   for (let col = 0; col < lengthArr; col++) {
  12.     for (let row = 0; row < lengthArr; row++)
  13.       arrSum += arr[col][row]
  14.     sums.push(arrSum)
  15.     arrSum = 0
  16.   }
  17.  
  18.   for (let i = 0; i < lengthArr; i++) {
  19.     arrSum = 0;
  20.  
  21.     for (let j = 0; j < lengthArr; j++) {
  22.       arrSum += arr[j][i];
  23.     }
  24.  
  25.     sums.push(arrSum);
  26.   }
  27.  
  28.   let equal = arr => arr.every(e => e === arr[0]);
  29.  
  30.   console.log(equal(sums));
  31. }
RAW Paste Data