You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
And none of these is prime. It will return true for any odd number, as you are skipping all of the odd number dividers (counter has a value of 2 + (n * 2)) on the line #17
for (let i = 2; i < Math.ceil(Math.sqrt(n)); i += 2) {
if (n % i === 0) {
return false
}
}
You just need to increment by 1 not by 2.
Cheers!
The text was updated successfully, but these errors were encountered:
Hello,
Thanks for putting this together, I was just browsing and noticed a bug in implementation of isPrime. It returns wrong results.
Try:
And none of these is prime. It will return true for any odd number, as you are skipping all of the odd number dividers (counter has a value of
2 + (n * 2)
) on the line #17You just need to increment by 1 not by 2.
Cheers!
The text was updated successfully, but these errors were encountered: