Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
You can make the isPrime method much more efficient by only checking against other prime numbers under p. Since you are building up the prime cache starting from 2 and working your way up there is no risk of missing primes.
I missed that the upper bound was Math.sqrt in my solution.
The reason this is very much not best practice is that it is very difficult for programmers to work together when type abstractions are violated. It is a great solution if the programmer is the only person that is ever going to rely on this code or need to modify it. If other programmers are involved, these sort of solutions can lead to unnecessary confusion and therefore bugs.
Also, if you are working on a personal project for long enough, you may look at a piece of code you did years ago and forget why your clever solution works or what it is meant to do.