Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function magicMatrices(arr) {
- let result = true;
- let rowCheck = arr[0].reduce((a, b) => a + b, 0);
- for (let i = 0; i < arr.length; i++) {
- let checkSum = arr[i].reduce((a, b) => a + b, 0);
- if (checkSum !== rowCheck) {
- result= false;
- break;
- }
- let checkRow = 0;
- for (let j = 0; j < arr.length; j++) {
- checkRow += arr[i][j];
- }
- if (checkRow !== rowCheck) {
- result = false;
- break;
- }
- checkRow = 0;
- }
- console.log(result ? 'true' : 'false')
- }
- magicMatrices([[4, 5, 6],
- [6, 5, 4],
- [5, 5, 5]]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement