Simple Explanation!
There is an obvious pattern to follow and it\'s simple : \nLeft side : you will notice that we add to the sum by increasing the index by one each  loop =>\n   [
There is an obvious pattern to follow and it\'s simple : \nLeft side : you will notice that we add to the sum by increasing the index by one each  loop =>\n   [****6****, 3, 1, 10, 7, 4],\n    [4, ****10****, 1, 9, 5, 10],\n    [5, 5, ****7****, 3, 8, 5],\n    [2, 7, 6, ****4****, 7, 6],\n    [7, 9, 6, 1, ****8****, 5],\n    [1, 7, 9, 5, 8, ****4****]]\n\t\nAlso from the right : we decrease the index by one \n  [6, 3, 1, 10, 7,****4****],\n    [4, 10, 1, 9, ****5****, 10],\n    [5, 5, 7, ****3****, 8, 5],\n    [2, 7, ****6****, 4, 7, 6],\n    [7, ****9****, 6, 1, 8, 5],\n    [****1****, 7, 9, 5, 8, 4]]\n\t\nAnd as for this case : \n    [1, 2, 3],\n    [4, 5, 6],\n    [7, 8, 9]\n\twhere we shoud only add num 5 to the sum only once, So the condition is :\n\tif right == left we only take one of them (because they are equal and both of them returns the same number).\n\t\n\tthe final solution\n\t\n```\nvar diagonalSum = function(mat) {\n  let left  = 0, right = mat.length-1, sum = 0;\n    for(let  i= 0; i < mat.length; i++) {\n        if(left == right) sum += mat[i][left];\n        else sum += mat[i][left] + mat[i][right];\n        left++;\n        right--;\n    }\n    return sum;\n};\n```\nUpvote if it was helpful
['Array', 'Matrix', 'JavaScript']