Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.