Created
March 22, 2018 08:25
-
-
Save dcustodio/0d85443b07f1929c20f05ed91f1d48b9 to your computer and use it in GitHub Desktop.
Calculating prime factors - exercism
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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