MCPcopy Create free account
hub / github.com/TheAlgorithms/JavaScript / PrimeFactors

Function PrimeFactors

Maths/PrimeFactors.js:6–20  ·  view source on GitHub ↗
(n)

Source from the content-addressed store, hash-verified

4*/
5
6export const PrimeFactors = (n) => {
7 // input: n: int
8 // output: primeFactors: Array of all prime factors of n
9 const primeFactors = []
10 for (let i = 2; i * i <= n; i++) {
11 while (n % i === 0) {
12 primeFactors.push(i)
13 n = Math.floor(n / i)
14 }
15 }
16 if (n > 1) {
17 primeFactors.push(n)
18 }
19 return primeFactors
20}

Callers 4

liouvilleFunctionFunction · 0.90
mobiusFunctionFunction · 0.90
isSquareFreeFunction · 0.90

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected