← Back to challenges

Count the Primes within a Range

JavaScriptHardloopsmathlogic

Instructions

Given two integers create a function that counts the number of primes between the two given integers.

Examples

primeCount(1, 10) ➞ 4
// range = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
// primes = [2, 3, 5, 7]
// answer = 4

primeCount(1, 100) ➞ 25

primeCount(1, 1000) ➞ 168

Notes

If there are no primes within the given range, return 0.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.