Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function magicMatrices(matrix) {
- for(let i = 0;i < matrix.length-1;i++){
- let rowOne = matrix[0].reduce((p,c,i,a)=> p + c,0);
- let rowTwo = matrix[1].reduce((p,c,i,a)=> p + c,0);
- let colOne = 0;
- let colTwo = 0;
- for(let a = 0;a < matrix.length;a++){
- colOne += matrix[i][a];
- colTwo += matrix[i + 1][a];
- }
- if(rowTwo != rowOne || colTwo != colOne){
- return false;
- }
- }
- return true;
- }
- console.log(magicMatrices(
- [[4, 5, 6],
- [6, 5, 4],
- [5, 5, 5]]
- ))
- console.log(magicMatrices(
- [[11, 32, 45],
- [21, 0, 1],
- [21, 1, 1]]
- ))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement