Search
 
SCRIPT & CODE EXAMPLE
 

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++;
    }     
  }
  return factors;
}
Comment

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;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: js get url parameter 
Javascript :: display loader on ajax call 
Javascript :: JavaScript create ul li from array 
Javascript :: afficher un div qui etait cache en javascript 
Javascript :: jquery loop through list elements 
Javascript :: pdf darkmode 
Javascript :: jquery validation on button click 
Javascript :: how to execute javascript after c# function execute 
Javascript :: javascript subtract days from date 
Javascript :: jquery prop checked 
Javascript :: how to copy text in react 
Javascript :: Access-Control-Allow-Origin 
Javascript :: Codewars Calculate average 
Javascript :: nodefetch of ES modules is not supported. 
Javascript :: js foreach determine if last 
Javascript :: react-native loading spinner 
Javascript :: usehistory not found in react-router-dom 
Javascript :: javascript clear sembols 
Javascript :: copy text to clipboard javascript react 
Javascript :: expo update react native 
Javascript :: axios try catch get error status cocxe 
Javascript :: jquery check input is disable 
Javascript :: javascript after dom ready 
Javascript :: jquery class list 
Javascript :: Angular detecting escape key press 
Javascript :: how to filter an array to only get numbers 
Javascript :: import formik 
Javascript :: divide intagers javascript 
Javascript :: react get input value on button click functional component 
Javascript :: get response from form jquery 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =