Created
August 16, 2020 15:41
-
-
Save Cihatata/df5c35dc89a65fe2a3a3fa2d944fed2e to your computer and use it in GitHub Desktop.
HackerRank Diagonal Difference js [SOLVED]
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) { | |
// Write your code here | |
let right=0; | |
let left=0; | |
let len = arr.length; | |
for(var i=0;i<len;i++){ | |
for(var j=0;j<len;j++){ | |
if(i - j == 0) { | |
left = left +arr[i][j]; | |
} | |
if (i + j == len -1) { | |
right = right +arr[i][j]; | |
} | |
} | |
} | |
return Math.abs(left - right); | |
} | |
var items = [ | |
[7, 2, 3], | |
[3, 4, 7], | |
[5, 6, -1] | |
]; | |
console.log(diagonalDifference(items)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment