Answers for "prime factorization javascript"

1

prime factorization javascript

function primeFactors(n){
  var factors = [], 
      divisor = 2;

  while(n>2){
    if(n % divisor == 0){
       factors.push(divisor); 
       n= n/ divisor;
    }
    else{
      divisor++;
    }     
  }
  return factors;
}
Posted by: Guest on June-25-2020
1

prime factorization javascript

function primeFactors(n){
  var factors = [], 
      divisor = 2;
  
  while(n>=2){
    if(n % divisor == 0){
       factors.push(divisor); 
       n= n/ divisor;
    }
    else{
      divisor++;
    }     
  }
	//contains duplicates, you should Array.prototype.filter() them out
  return factors;
}
Posted by: Guest on January-02-2021

Code answers related to "prime factorization javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language