Created
October 6, 2016 11:04
-
-
Save a-eid/71d30f7260fc46d53e5e76de77d7c1f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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