Skip to content

Instantly share code, notes, and snippets.

@a-eid
Created October 6, 2016 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a-eid/71d30f7260fc46d53e5e76de77d7c1f1 to your computer and use it in GitHub Desktop.
Save a-eid/71d30f7260fc46d53e5e76de77d7c1f1 to your computer and use it in GitHub Desktop.
isPrime = function(x){
// if number is 1 , 0 or negative it is not a prime
if(x <= 1) return false;
if(x == 2) return true ;
for( var i = x - 1 ; i > 1 ; i-- ){
console.log(x + ' % ' + i + " " + x % i );
if(x % i == 0) return false;
}
return true;
}
var find_next_prime= function(n){
var i = n + 1;
while(!isPrime(i)){
i++;
}
return i;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment