http://gengns.com/wp-content/uploads/2015/05/logo-onepage-300x66.png00Génesishttp://gengns.com/wp-content/uploads/2015/05/logo-onepage-300x66.pngGénesis2018-07-03 13:14:522018-07-03 13:28:12Find factors of a number
2replies
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)), []);
Génesis says:
More complex but better mathematical approach japanfever 👏
//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)), []);
More complex but better mathematical approach japanfever 👏