Advertisement
fbinnzhivko

Untitled

Oct 2nd, 2016
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function magic_Matrix(input) {
  2.  
  3.     let matrix = [];
  4.     for (let r = 0; r < input.length; r++) {
  5.         let line = input[r].split(' ').map(Number);
  6.         matrix.push(line);
  7.     }
  8.     let sum = matrix[0].reduce((a, b) => (a + b));  //сума на първия ред
  9.  
  10.  
  11.     for (let row = 1; row < input.length; row++) {
  12.         let sumRow = matrix[row].reduce((a, b) => (a + b));
  13.  
  14.         if (sum != sumRow) { // ака сумата на n ред не съвпада с първия ред
  15.             return false;
  16.         }
  17.         else{
  18.             return true;
  19.         }
  20.     }
  21. }
  22. //console.log(magic_Matrix(['11 32 45', '21 0 1', '21 1 1']));
  23. //console.log(magic_Matrix(['1 0 0', '0 0 1', '0 1 0']));
  24. console.log(magic_Matrix(['4 5 6', '6 5 4', '5 5 5']));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement