Skip to the code
cf.
+10 XP

#646 Prime Factors of a Bundle Size

easy

A bundler report shows each chunk's size in bytes. To explain how evenly a chunk can be split, it lists the size's prime factors.

Write primeFactorsOf(n) that returns the prime factors of n in ascending order, with each prime repeated as many times as it divides n. For n = 1, return [].

Example 1

Input: n = 12
Output: [2,2,3]

12 = 2 × 2 × 3.

Example 2

Input: n = 13
Output: [13]

13 is prime, so it is its own only prime factor.

Constraints

  • 1 <= n <= 10^12
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).