← Back to challenges

Complete Prime Factorization

JavaScriptHardarraysmath

Instructions

Create a function that decomposes an integer into its prime factors, ordered from smallest to largest.

For instance:

completeFactorization(24) = [2, 2, 2, 3]
// Since 24 = 8 x 3 = 2^3 x 3 = 2 x 2 x 2 x 3

Examples

completeFactorization(10) ➞ [2, 5]

completeFactorization(9) ➞ [3, 3]

completeFactorization(72) ➞ [2, 2, 2, 3, 3]

Notes

1 is not considered a prime number, so omit it in your final array of prime factors.

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