Pointer | Function to find the product of digits of a number N ; Function that returns true if n is prime else returns false ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; Function to return the smallest prime number greater than N ; Base case ; Loop continuously until isPrime returns true for a number greater than n ; Function to check Pointer - Prime numbers ; Given Number N ; Function Call
function digProduct ( n ) { var product = 1 ; while ( n != 0 ) { product = product * ( n % 10 ) ; n = parseInt ( n / 10 ) ; } return product ; } function isPrime ( n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( var i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } function nextPrime ( N ) { if ( N <= 1 ) return 2 ; var prime = N ; var found = false ; while ( ! found ) { prime ++ ; if ( isPrime ( prime ) ) found = true ; } return prime ; } function isPointerPrime ( n ) { if ( isPrime ( n ) && ( n + digProduct ( n ) == nextPrime ( n ) ) ) return true ; else return false ; } var N = 23 ; if ( isPointerPrime ( N ) ) document . write ( " " ) ; else document . write ( " " ) ;