function isPrime(num) {
if (num === 2) {
return true
} else if (num % 2 === 0) {
return false
}
let sqrt = parseInt(Math.sqrt(num))
for (let i = 3; i <= sqrt; i = i + 2) {
if (num % i === 0) {
return false
}
}
return true
}
Prime number check
One minute to read