Prime Numbers Flashcards
1
Q
Determine if a number is prime?
A
function primeTester (n) { var sqrt = Math.sqrt(n); if(n \<= 1 || n % 2 === 0){ if(n === 2){ return true; } return false; }
for(var i = 3; i \<= sqrt; i+=2){ if(n % i === 0){ return false; } } return true; }