📜  素数分解javascript代码示例

📅  最后修改于: 2022-03-11 15:02:40.209000             🧑  作者: Mango

代码示例2
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;
}