Skip to content

Instantly share code, notes, and snippets.

@merss19
Last active December 15, 2016 08:45
Show Gist options
  • Save merss19/c87826b1e687146ace4530a692b134cd to your computer and use it in GitHub Desktop.
Save merss19/c87826b1e687146ace4530a692b134cd to your computer and use it in GitHub Desktop.
let mat = [
[ 1, 2, 3, 4 ],
[ 4, 5, 6, 5 ],
[ 7, 8, 9, 7 ],
[ 7, 8, 9, 7 ]
];
function sumUpDiagonals(matrix,bool) {
if(bool){
matrix= matrix.reverse()
}
let result = 0,
matrixLen = matrix.length
for (i=0; i<matrixLen; i++){
let len = matrix[i].length
for (j=0;j<len;j++){
if (i ===j){
result +=matrix[i][j] }
}
}
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment