Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added solution to largest prime factor #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions solutions/fibonacci-add-even.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
// console.log(fiboAddEven(1, 4000000));
25 changes: 25 additions & 0 deletions solutions/largest-prime-factor.js
Original file line number Diff line number Diff line change
@@ -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<target) {

while(target%i === 0) {

(function(newtarget) {
target = newtarget;
})(target / i)
}
i++;
}
return target;
}

// Test
// console.log(largestPrimeFactor(600851475143));