← Back to challenges

Primes Below a Given Number

JavaScriptHardalgebramathnumbersloops

Instructions

Create a function that will find all primes below a given number. Return the result as an array.

Examples

primesBelowNum(5) ➞ [2, 3, 5]

primesBelowNum(10) ➞ [2, 3, 5, 7]

primesBelowNum(20) ➞ [2, 3, 5, 7, 11, 13, 17, 19]

Notes

If n is a prime, include it in the array.

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