DEV Community

Discussion on: Prime numbers

Collapse
 
jamesrweb profile image
James Robb • Edited

You make a good point, I hadn’t considered that actually!

If I was to add this change it would just replace the conditional at the beginning of the function body which checks if the number is even and greater than 2 so this shouldn’t ever execute unless it’s an odd number that is passed in as input, in which case this becomes a good performance improvement, especially for larger numbers since odd numbers aren’t divisible by even ones without a remainder being present of course.

Thanks for commenting! 👍