From 774e4965d2c8bb479ed3b85fe71a35292734fecd Mon Sep 17 00:00:00 2001 From: Mmakwe Onyeka Date: Sun, 1 Apr 2018 21:31:32 +0100 Subject: [PATCH] Added solution to largest prime factor --- solutions/fibonacci-add-even.js | 4 ++-- solutions/largest-prime-factor.js | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 solutions/largest-prime-factor.js diff --git a/solutions/fibonacci-add-even.js b/solutions/fibonacci-add-even.js index ded416e..ef5047e 100644 --- a/solutions/fibonacci-add-even.js +++ b/solutions/fibonacci-add-even.js @@ -24,11 +24,11 @@ function fiboAddEven(start, limit) { // filter out all items that are even and add them up var result = 0; fibArray.forEach(function(eachItem){ - if (eachItem % 2 === 0) result += eachItem; + if (eachItem % 2 === 0) result += eachItem; }); return result; } // Test -// console.log(fiboAddEven(1, 4000000)); \ No newline at end of file +// console.log(fiboAddEven(1, 4000000)); diff --git a/solutions/largest-prime-factor.js b/solutions/largest-prime-factor.js new file mode 100644 index 0000000..9da972e --- /dev/null +++ b/solutions/largest-prime-factor.js @@ -0,0 +1,25 @@ +//The prime factors of 13195 are 5, 7, 13 and 29. +//What is the largest prime factor of the number 600851475143 ? + +function largestPrimeFactor(originalTarget){ + if ((typeof originalTarget !== "number" || originalTarget === 0)){ + return "Arguments supplied to fn fiboEvenAdd must a natural integer"; + } + + var target = originalTarget; + var i = 2; + while(i