Created
July 11, 2018 13:18
-
-
Save sp1r1don/3a481fa008525d8a2187f3e15a0388ae to your computer and use it in GitHub Desktop.
pyshop tasks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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