Skip to content

Instantly share code, notes, and snippets.

@OlukaDenis
Created August 17, 2019 05:15
Show Gist options
  • Save OlukaDenis/e09b03a233bd16cac03efe1d1e8a1569 to your computer and use it in GitHub Desktop.
Save OlukaDenis/e09b03a233bd16cac03efe1d1e8a1569 to your computer and use it in GitHub Desktop.
Solution for HackerRank > Algorithms > Warmup > Diagonal difference
function diagonalDifference(arr) {
let left_diagonal = 0
let right_diagonal = 0
let total = 0
for (let i = 0; i < arr.length; i++){
left_diagonal += arr[i][i]
right_diagonal += arr[arr.length - 1 - i][i]
total = Math.abs(left_diagonal - right_diagonal)
}
return total
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment