Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function isMagixMatrix (matrix) {
- let sum = matrix[0].reduce((a, b) => a + b, 0)
- let isMagic = true
- matrix.forEach((row, index) => {
- let horizontalSum = row.reduce((a, b) => a + b, 0)
- let verticalSum = matrix.map(arr => arr[index]).reduce((a, b) => a + b, 0)
- if (horizontalSum !== sum || verticalSum !== sum) {
- isMagic = false
- }
- })
- console.log(isMagic)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement