Created
August 17, 2019 05:15
-
-
Save OlukaDenis/e09b03a233bd16cac03efe1d1e8a1569 to your computer and use it in GitHub Desktop.
Solution for HackerRank > Algorithms > Warmup > Diagonal difference
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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