code.ashish.me

Atom feed

Recently added: 02 Count Of Subset Sum, 416 Partition Equal Subset Sum, 01 Subset Sum, 518 Coin Change 2, 983 Minimum Cost For Tickets

03 Largest Prime Factor

function largestPrimeFactor(number) {
  const factors = [];
  let d = 2;
  while (number > 1) {
    if (number % d === 0) {
      factors.push(d);
      number /= d;
    }
    d += 1;
  }
  return Math.max(...factors);
}

console.log(largestPrimeFactor(13195));

Created 2019-11-24T04:41:20+05:18 · Edit