← Back to challenges

Prime Factorization of an Integer

JavaScriptHardmathnumbersalgorithmsloops

Instructions

Create a function that returns an array containing the prime factors of whatever integer is passed to it.

Examples

primeFactors(20) ➞ [2, 2, 5]

primeFactors(100) ➞ [2, 2, 5, 5]

primeFactors(8912234) ➞ [2, 47, 94811]

Notes

  • Implement your solution using trial division.
  • Your solution should not require recursion.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.