Implementation of Wilson Primality test | Function to calculate the factorial ; Function to check if the number is prime or not ; Driver code
function fact ( p ) { if ( p <= 1 ) return 1 ; return p * fact ( p - 1 ) ; } function isPrime ( p ) { if ( p == 4 ) return false ; if ( fact ( p >> 1 ) % p == 0 ) { return 0 ; } return 1 ; } document . write ( isPrime ( 127 ) ) ;