showing results for - "prime factorization javascript"
Liam
04 Jan 2019
1function primeFactors(n){
2  var factors = [], 
3      divisor = 2;
4
5  while(n>2){
6    if(n % divisor == 0){
7       factors.push(divisor); 
8       n= n/ divisor;
9    }
10    else{
11      divisor++;
12    }     
13  }
14  return factors;
15}
Lilly
11 Aug 2016
1function primeFactors(n){
2  var factors = [], 
3      divisor = 2;
4  
5  while(n>=2){
6    if(n % divisor == 0){
7       factors.push(divisor); 
8       n= n/ divisor;
9    }
10    else{
11      divisor++;
12    }     
13  }
14	//contains duplicates, you should Array.prototype.filter() them out
15  return factors;
16}
17