Find factors of a number

2 replies
  1. japanfever
    japanfever says:


    //factors is O(n), factorsfaster is O(sqrt(n)) by E3839EE383AAE382AAE9B3A9E38388E383ACE383AD
    const factorsfaster = num =>
    [...Array(parseInt(Math.sqrt(num))+1).keys()]
    .reduce((o, i) => num % i != 0 ? o : (num / i == i ? o.concat(i) : o.concat(i,num/i)), []);

Comments are closed.