function getPrimeFactors(n) {
const factors = [];
let divisor = 2;
while (n >= 2) {
if (n % divisor === 0) {
factors.push(divisor);
n /= divisor;
} else {
divisor++;
}
}
return factors;
}
const n = 124;
console.log(getPrimeFactors(n)); // 2 x 2 x 31
console.log(getPrimeFactors(288)); // 2 x 2 x 2 x 2 x 2 x 3 x 3
console.log(getPrimeFactors(1288)); // 2 x 2 x 2 x 7 x 23
/*
run:
[ 2, 2, 31 ]
[ 2, 2, 2, 2, 2, 3, 3 ]
[ 2, 2, 2, 7, 23 ]
*/