Find next palindrome prime | Javascript program to find next palindromic prime for a given number . ; if ( 8 <= N <= 11 ) return 11 ; generate odd length palindrome number which will cover given constraint . ; if y >= N and it is a prime number then return it . ; Driver code
function isPrime ( num ) { if ( num < 2 num % 2 == 0 ) return num == 2 ; for ( i = 3 ; i * i <= num ; i += 2 ) if ( num % i == 0 ) return false ; return true ; } function primePalindrome ( N ) { if ( 8 <= N && N <= 11 ) return 11 ; for ( let x = 1 ; x < 100000 ; ++ x ) { let s = String ( x ) ; let r = s . split ( " " ) . reverse ( ) . join ( " " ) ; let y = parseInt ( s + r . substr ( 1 ) ) ; if ( y >= N && isPrime ( y ) == true ) return y ; } return - 1 ; } document . write ( primePalindrome ( 112 ) ) ;