Tell us what’s happening:
Hi, I think that there may be a problem with the tests for this challenge. The test fails saying:
largestPrimeFactor(600851475143) should return 6857.
However, when i run my code in the console then I do get 6857 as my answer. Please could you check that the tests are running correctly?
Thanks!
Your code so far
function largestPrimeFactor(number) {
if(isPrime(number)) return number;
for(let i = Math.floor(Math.sqrt(number)); i >= 2; i--) {
if(isPrime(i) && number % i === 0) return i;
}
return 2;
}
function isPrime(n) {
if(n < 2) return false
for(let i = 2; i <= Math.floor(Math.sqrt(n)); i++) {
if(n % i === 0) return false;
}
return true;
}
largestPrimeFactor(13195);
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/coding-interview-prep/project-euler/problem-3-largest-prime-factor/