Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

prime factors of an integer js

function primeFactors(n) {
  const factors = [];
  let divisor = 2;

  while (n >= 2) {
    if (n % divisor == 0) {
      factors.push(divisor);
      n = n / divisor;
    } else {
      divisor++;
    }
  }
  return factors;
}

const randomNumber = Math.floor(Math.random() * 10000);
console.log('Prime factors of', randomNumber + ':', primeFactors(randomNumber).join(' '))
 Run code snippet
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to get min value from array of objects in javascript 
Javascript :: object filter 
Javascript :: Add a mirgation in sequelize 
Javascript :: ContentDocumentLink example in jS 
Javascript :: clone copy a table in servicenow 
Javascript :: speed of sound 
Javascript :: call url many times 
Javascript :: how to get node modules 
Javascript :: react native paper touchable ripple 
Javascript :: how to end tsc main --watch 
Javascript :: arrow function with computed property vue 
Javascript :: React Tools - Suspense 
Javascript :: how to import kakao login page to navbar in react 
Javascript :: javascript get element by class domlist undefined 
Javascript :: email validation in form using javascript 
Javascript :: my code agly because alot of if and else dev community 
Javascript :: Finding Attribute value with playwright in node.js 
Javascript :: jquery crud table example 
Javascript :: typeorm not supporrtted insert large data 
Javascript :: how to test conditional rendering vue test utils 
Javascript :: javascript float not showing 0 
Javascript :: observables loop in template angular 8 
Javascript :: Rest and spread operators in ES6 
Javascript :: material ui table row onclick 
Javascript :: image support in node js chat app 
Javascript :: nodejs mongoose connec tion 
Javascript :: animateOut: "slideOutUp", animateIn: "slideInUp", not working 
Javascript :: module missing for arearange highcharts react 
Javascript :: browserslist 
Javascript :: react Update a label when rate moves "quietly" 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =