Answers for "verify prime number"

0

verify prime number

How to verify a prime number in javascript ?
Posted by: Guest on September-29-2021
0

verify a prime number

function isPrime(n){
  var divisor = 2;

  while (n > divisor){
    if(n % divisor == 0){
     return false; 
    }
    else
      divisor++;
  }
  return true;
}

> isPrime(137);
  = true
> isPrime(237);
  = false
Posted by: Guest on September-29-2021

Browse Popular Code Answers by Language