Project Euler problem 3: Largest prime factor in JavaScript I have created a soloution for Project Euler: Problem 3 - Largest Prime Factor in JavaScript:

function isPrime(value) {
    for (var i = 2; i &lt; value; i++) {
        if (value % i == 0) {
            return false;
        }
    }
    return true;
}

function findFactors(value) {
    var array = [];
    for (var i = 2; i &lt; value; i++) {
        if (value % i == 0) {
            array.push(i);
        }
    }
    return array;
}

function findPrimeFactors(value) {
    var array = [];
    for (var i = 0; i &lt; findFactors(value).length; i++) {
        if (isPrime(findFactors(value)[i])) {
            array.push(findFactors(value)[i]);
        }
    }
    return array;
}

document.write("Answer: " + Math.max(...findPrimeFactors(600851475143)));


I would like to know if my code even works, as it is so slow, that even when I left it for 20 minutes it still didn't finish, and if so, I would like to know a quick way of doing it (If my code would actually give it) so I can mark it as completed.
Your code looks pretty, and it is a very literal naïve implementation of the requirements. Unfortunately, the algorithm you are using is extremely inefficient.

Factoring large numbers is hard work! The difficulty of factoring large numbers is, in fact, what keeps cryptographic algorithms like RSA safe.  In your findFactors() function, just counting up to 600 billion will take a while; having to check for divisibility within the loop is even slower!

For a quick algorithm that will give the answer in about one second, see this answer.