Prime Factorization of an Integer

Published by Mubashir Hassan in

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.
Watch a quick demo on how Edabit works.