Node.js program to find if number is prime
function isPrime(num) {
if(num < 2) return false
var maxDivider = Math.floor(Math.sqrt(num))
for (i = 2; i < maxDivider; i++) {
if (num % i == 0) return false
}
return true;
}
console.log("IsPrime ",isPrime(3))
No comments:
Post a Comment