Skip to content

Instantly share code, notes, and snippets.

View hannahintech's full-sized avatar

Hannah Tucker McLellan hannahintech

View GitHub Profile
@lasverg
lasverg / diagonal-difference.js
Last active May 29, 2023 06:34
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.