Prime o no en JavaScript
function isPrime(num) {
for(var i = 2; i < num; i++)
if(num % i === 0) return false;
return num > 1;
}
Troubled Trout
function isPrime(num) {
for(var i = 2; i < num; i++)
if(num % i === 0) return false;
return num > 1;
}
function isPrime(num) {
for (let i = 2; i * i <= num; i++)
if (num % i === 0)
return false;
return num > 1;
}
function isPrime(num) {
if (num <= 1) return false;
if (num == 2) return true;
for (let i = 2; i <= num / 2; i++) {
if (num % i == 0) {
return false;
}
}
return true;
}
console.log(isPrime(2));
console.log(isPrime(53));