Skip to content

Instantly share code, notes, and snippets.

@themonster2015
Created October 1, 2021 07:20
Show Gist options
  • Save themonster2015/917ecba580886e58f5bdf2cf8dbdd3ec to your computer and use it in GitHub Desktop.
Save themonster2015/917ecba580886e58f5bdf2cf8dbdd3ec to your computer and use it in GitHub Desktop.
//https://www.hackerrank.com/challenges/diagonal-difference/problem?isFullScreen=true
function diagonalDifference(arr) {
let sum1 = 0, sum2 = 0
for(let i = 0; i < arr.length; i++ ){
sum1 += arr[i][i]
let j = arr.length - 1 - i
sum2 += arr[i][j]
//console.log(arr[i][j])
}
return Math.abs(sum1 - sum2)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment