emotrend

Untitled

Feb 4th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. function solve(matrix) {
  2. let rowSum = 0;
  3.  
  4. for (let row = 0; row < matrix.length; row++) {
  5. let currRowSum = 0;
  6.  
  7. for (let col = 0; col < matrix[row].length; col++) {
  8. currRowSum += matrix[row][col];
  9. }
  10.  
  11. if (row === 0) {
  12. rowSum = currRowSum;
  13. } else if (rowSum !== currRowSum) {
  14. return false;
  15. }
  16. }
  17.  
  18. for (let col = 0; col < matrix[0].length; col++) {
  19. let currColSum = 0;
  20.  
  21. for (let row = 0; row < matrix.length; row++) {
  22. currColSum += matrix[row][col];
  23. }
  24.  
  25. if (currColSum !== rowSum) {
  26. return false;
  27. }
  28. }
  29.  
  30. return true;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment