Skip to content

Instantly share code, notes, and snippets.

@dcustodio
Created March 22, 2018 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcustodio/0d85443b07f1929c20f05ed91f1d48b9 to your computer and use it in GitHub Desktop.
Save dcustodio/0d85443b07f1929c20f05ed91f1d48b9 to your computer and use it in GitHub Desktop.
Calculating prime factors - exercism
var primeFactors = function () {}
primeFactors.prototype.for = function (num) {
return calcPrimeFactor([], num)
}
var calcPrimeFactor = function (arr, num) {
for (var i = 2; i <= num; i++) {
if (num % i === 0) {
arr.push(i)
return calcPrimeFactor(arr, num / i);
}
}
return arr;
}
module.exports = primeFactors;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment