You are viewing a single comment's thread. Return to all comments →
Nice. You can remove the conditional though, and complete this in one loop. Here is my solution in JavaScript.
let primaryDiag = 0 let secondDiag = 0 let length = Matrix.length for (var i = 0, indexLength = length - 1; i < length; i++) { primaryDiag += Matrix[i][i] secondaryDiag += Matrix[i][indexLength] indexLength -= 1 } return Math.abs(primaryDiag - secondaryDiag)
Seems like cookies are disabled on this browser, please enable them to open this website
Diagonal Difference
You are viewing a single comment's thread. Return to all comments →
Nice. You can remove the conditional though, and complete this in one loop. Here is my solution in JavaScript.