Check if a number is Full Prime | function to check digits ; check all digits are prime or not ; check if digits are prime or not ; To check if n is prime or not ; check for all factors ; To check if n is Full Prime ; The order is important here for efficiency ; Driver Code
function checkDigits ( n ) { while ( n > 0 ) { let dig = n % 10 ; if ( dig != 2 && dig != 3 && dig != 5 && dig != 7 ) return false ; n = parseInt ( n / 10 , 10 ) ; } return true ; } function prime ( n ) { if ( n == 1 ) return false ; for ( let i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) return false ; } return true ; } function isFullPrime ( n ) { return ( checkDigits ( n ) && prime ( n ) ) ; } let n = 53 ; if ( isFullPrime ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;