Advertisement
deddyprianto

DIAGONAL REFERENCE

Jan 5th, 2022
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const dataArr = [
  2.   [1, 2, 3],
  3.   [4, 5, 6],
  4.   [9, 8, 9],
  5. ];
  6. let diag1 = 0;
  7. for (let i = 0; i < dataArr.length; i++) {
  8.   for (let j = 0; j < dataArr.length; j++) {
  9.     if (i === j) {
  10.       diag1 += dataArr[i][j];
  11.     }
  12.     if (i + j === dataArr.length - 1) {
  13.       diag2 += dataArr[i][j];
  14.     }
  15.  
  16.   }
  17. }
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement