Skip to content

Instantly share code, notes, and snippets.

@sp1r1don
Created July 11, 2018 13:18
Show Gist options
  • Save sp1r1don/3a481fa008525d8a2187f3e15a0388ae to your computer and use it in GitHub Desktop.
Save sp1r1don/3a481fa008525d8a2187f3e15a0388ae to your computer and use it in GitHub Desktop.
pyshop tasks
var matrixExample = [
[ 1, 2, 3, 4 ],
[ 4, 5, 6, 5 ],
[ 7, 8, 9, 7 ],
[ 7, 8, 9, 7 ]
];
function sumUpDiagonals(matrix) {
var sumMain = 0;
var sumSec = 0;
for (var i = 0; matrix.length > i; i++){
sumMain += matrix[i][i];
sumSec += matrix[i][matrix.length - i - 1];
}
return 'Сумма основной диагонали: ' + sumMain + '\nСумма вторичной диагонали: ' + sumSec;
};
console.log(sumUpDiagonals(matrixExample));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment