Implementing Algorithm to Find Primes - Javascript