Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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;
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #prime #factorization #javascript
ADD COMMENT
Topic
Name
9+8 =