Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function magic_Matrix(input) {
- let matrix = [];
- for (let r = 0; r < input.length; r++) {
- let line = input[r].split(' ').map(Number);
- matrix.push(line);
- }
- let sum = matrix[0].reduce((a, b) => (a + b)); //сума на първия ред
- for (let row = 1; row < input.length; row++) {
- let sumRow = matrix[row].reduce((a, b) => (a + b));
- if (sum != sumRow) { // ака сумата на n ред не съвпада с първия ред
- return false;
- }
- else{
- return true;
- }
- }
- }
- //console.log(magic_Matrix(['11 32 45', '21 0 1', '21 1 1']));
- //console.log(magic_Matrix(['1 0 0', '0 0 1', '0 1 0']));
- console.log(magic_Matrix(['4 5 6', '6 5 4', '5 5 5']));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement