Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js is prime

function isPrime(num) {
  if(num === 2) return true;
  if(num % 2 === 0) return false;
  for(var i = 3; i <= Math.sqrt(num); i += 2){
    if(num % i === 0) return false;
  }
  return num > 1;
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #js #prime
ADD COMMENT
Topic
Name
9+6 =