Skip to content

Instantly share code, notes, and snippets.

@cobiwave
cobiwave / diagonal-difference.js
Created September 12, 2018 14:45 — forked from lasverg/diagonal-difference.js
Diagonal Difference | Solution | JavaScript
/*
Diagonal Difference Solution.
sample matrix = [[1,2,3], [4,5,6], [7,8,9]]
*/
function diagonalDifference(matrix) {
// length of input matrix.
const length = matrix.length;
let diagonal1 = 0, diagonal2 = 0;
// Looping through the array and summing the diagonals.