Count non | Function to reverse a number ; Store the reverse of N ; Return reverse of N ; Function to get the count of non - palindromic numbers having same first and last digit ; Store the required count ; Traverse the array ; Store reverse of arr [ i ] ; Check for palindrome ; IF non - palindromic ; Check if first and last digits are equal ; Driver Code
function revNum ( N ) { var x = 0 ; while ( N ) { x = x * 10 + ( N % 10 ) ; N = N / 10 ; } return x ; } function ctNonPalin ( arr , N ) { var Res = 0 ; for ( var i = 0 ; i < N ; i ++ ) { var x = revNum ( arr [ i ] ) ; if ( x == arr [ i ] ) { continue ; } else { Res += arr [ i ] % 10 == N % 10 ; } } return Res ; } var arr = [ 121 , 134 , 2342 , 4514 ] ; var N = arr . length ; document . write ( ctNonPalin ( arr , N ) ) ;