Skip to content

Instantly share code, notes, and snippets.

View JuanFCVal's full-sized avatar
🧨
Learning

Juan Francisco Cevallos Valdivieso JuanFCVal

🧨
Learning
  • Torre
  • Loja, Ecuador
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.