To get P , S , MR , and MC
for ( let i = 0 ; i < mat . length ; i ++ ) { for ( let j = 0 ; j < mat [ 0 ] . length ; j ++ ) { if ( i == j ) P . push ( mat [ i ] [ j ] ) ; if ( i + j == mat . length - 1 ) S . push ( mat [ i ] [ j ] ) ; if ( i == Math . floor ( ( mat . length - 1 ) / 2 ) ) MR . push ( mat [ i ] [ j ] ) ; if ( j == Math . floor ( ( mat . length - 1 ) / 2 ) ) MC . push ( mat [ i ] [ j ] ) ; } } S . reverse ( ) ;