← Back to challenges

Any Prime Number in Range

JavaScriptHardalgebraalgorithmsmathnumbers

Instructions

Create a function that returns true if there's at least one prime number in the given range (n1 to n2 (inclusive)), false otherwise.

Examples

primeInRange(10, 15) ➞ true
// Prime numbers in range: 11, 13

primeInRange(62, 66) ➞ false
// No prime numbers in range.

primeInRange(3, 5) ➞ true
// Prime numbers in range: 3, 5

Notes

  • n2 is always greater than n1.
  • n1 and n2 are always positive.
  • 0 and 1 aren't prime numbers.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.