Traverse the matrix in Diagonally Bottum | Static variable for changing row and column ; Flag variable for handling bottum up diagonal traversing ; Recursive function to traverse the matrix diagonally bottom - up ; Base Condition ; Condition when to traverse Bottom Diagonal of the matrix ; Print matrix cell value ; Recursive function to traverse The matrix diagonally ; Recursive function to change diagonal ; Initialize the 5 x 5 matrix ; Function call for traversing matrix
let k1 = 0 , k2 = 0 ; let flag = true ; function traverseMatrixDiagonally ( m , i , j , row , col ) { if ( i >= row j >= col ) { if ( flag ) { let a = k1 ; k1 = k2 ; k2 = a ; flag = ! flag ; k1 ++ ; } else { let a = k1 ; k1 = k2 ; k2 = a ; flag = ! flag ; } document . write ( " " ) ; return false ; } document . write ( m [ i ] [ j ] + " " ) ; if ( traverseMatrixDiagonally ( m , i + 1 , j + 1 , row , col ) ) { return true ; } if ( traverseMatrixDiagonally ( m , k1 , k2 , row , col ) ) { return true ; } return true ; } let mtrx = [ [ 10 , 11 , 12 , 13 , 14 ] , [ 15 , 16 , 17 , 18 , 19 ] , [ 20 , 21 , 22 , 23 , 24 ] , [ 25 , 26 , 27 , 28 , 29 ] , [ 30 , 31 , 32 , 33 , 34 ] ] ; traverseMatrixDiagonally ( mtrx , 0 , 0 , 5 , 5 ) ;