Task of Challange #19
Create a function that will return in an array the first “nPrimes” prime numbers greater than a particular number “startAt”
Solution
Explanation
The function getPrimes
has to accept two parameters. nPrimes
which decides the number of prime numbers we want to get out and startAt
which decides where we start to examine the prime numbers.
We create an empty array
and set our runningIndex i
equal to the startAt
variable.
A while loop makes a continuous call to the isPrime
function and passes in the number we want to check. This is being done as long as our array is below the nPrimes
variable.
So once we have the predestined number of primes, we will skip the while loop and return the array with prime numbers.
I have already explained the isPrime
function in Challenge #18.
For example if you call this function with console.log(getPrimes(10, 100));
then the following picture is the output.

Follow me on Instagram and don’t miss the latest Challenge!
https://www.instagram.com/arnold.code/
Become a bullet proof developer and seek my coding adventures on Udemy
https://www.udemy.com/user/arnold-abraham-3/
Don’t Miss My Most Read Article with over 8000 Views
One Reason Not to Migrate From JavaScript to TypeScript
Typescript saves a lot of development time, but is it worth an entire migrating process?

Get Your JavaScript Coding To A Very Professional Level with this article
Upgrade Your Legacy Coding Style With These 6 Modern Ways of Coding

And How These 3 Famous TV Shows Make You Write Excellent JavaScript Code