← Back to challenges

Prime Divisors

JavaScriptHardmathalgorithmsnumbers

Instructions

Given a number, return all its prime divisors in an array. Create a function that takes a number as an argument and returns all its prime divisors.

To illustrate:

  • If n = 27
  • All divisors are: [3, 9, 27]
  • Finally, from that array of divisors, return the prime ones: [3]

Examples

primeDivisors(27) ➞ [3]

primeDivisors(99) ➞ [3, 11]

primeDivisors(3457) ➞ [3457]

Notes

N/A

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