Check if a given matrix is Hankel or not | Function to check if given matrix is Hankel Matrix or not . ; for each row ; for each column ; checking if i + j is less than n ; checking if the element is equal to the corresponding diagonal constant ; checking if the element is equal to the corresponding diagonal constant ; Drivers code
function checkHankelMatrix ( n , m ) { for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { if ( i + j < n ) { if ( m [ i ] [ j ] != m [ i + j ] [ 0 ] ) return false ; } else { if ( m [ i ] [ j ] != m [ i + j - n + 1 ] [ n - 1 ] ) return false ; } } } return true ; } let n = 4 ; let m = [ [ 1 , 2 , 3 , 5 ] , [ 2 , 3 , 5 , 8 ] , [ 3 , 5 , 8 , 0 ] , [ 5 , 8 , 0 , 9 ] ] ; if ( checkHankelMatrix ( n , m ) ) document . write ( " " ) ; else document . write ( " " ) ;