Advertisement
nikolayneykov

Untitled

May 30th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function isMagixMatrix (matrix) {
  2.   let sum = matrix[0].reduce((a, b) => a + b, 0)
  3.   let isMagic = true
  4.  
  5.   matrix.forEach((row, index) => {
  6.     let horizontalSum = row.reduce((a, b) => a + b, 0)
  7.     let verticalSum = matrix.map(arr => arr[index]).reduce((a, b) => a + b, 0)
  8.  
  9.     if (horizontalSum !== sum || verticalSum !== sum) {
  10.       isMagic = false
  11.     }
  12.   })
  13.  
  14.   console.log(isMagic)
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement