Check if the given two matrices are mirror images of one another | Function to check whether the two matrices are mirror of each other ; Initialising row and column of second matrix ; Iterating over the matrices ; Check row of first matrix with reversed row of second matrix ; If the element is not equal ; Increment column ; Reset column to 0 for new row ; Increment row ; Given 2 matrices ; Function Call
function mirrorMatrix ( mat1 , mat2 , N ) { let row = 0 ; let col = 0 ; let isMirrorImage = true ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = N - 1 ; j >= 0 ; j -- ) { if ( mat2 [ row ] [ col ] != mat1 [ i ] [ j ] ) { isMirrorImage = false ; } col ++ ; } col = 0 ; row ++ ; } if ( isMirrorImage ) document . write ( " " ) ; else document . write ( " " ) ; } let N = 4 ; let mat1 = [ [ 1 , 2 , 3 , 4 ] , [ 0 , 6 , 7 , 8 ] , [ 9 , 10 , 11 , 12 ] , [ 13 , 14 , 15 , 16 ] ] ; let mat2 = [ [ 4 , 3 , 2 , 1 ] , [ 8 , 7 , 6 , 0 ] , [ 12 , 11 , 10 , 9 ] , [ 16 , 15 , 14 , 13 ] ] ; mirrorMatrix ( mat1 , mat2 , N ) ;