Ledger Nano X - The secure hardware wallet
SHARE
TWEET

magic-matrix

milengerov May 22nd, 2020 1,059 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function checkMagic(matrix) {
  2.  
  3.     function sumRow(row) {
  4.         return row.reduce((a, b) => a + b);
  5.  
  6.     }
  7.  
  8.     const transposedMatrix = matrix.map((col, i) => matrix.map(row => row[i]));
  9.  
  10.     const firstRowSum = sumRow(matrix[0]);
  11.     let magickMatrix = true;
  12.  
  13.     for (let i = 0; i < matrix.length; i++) {
  14.         if (sumRow(matrix[i]) !== firstRowSum || sumRow(transposedMatrix[i]) !== firstRowSum) {
  15.             magickMatrix = false;
  16.             break;
  17.         }
  18.     }
  19.  
  20.     console.log(magickMatrix)
  21.  
  22. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top