Smallest Common Multiple failing last test

Smallest Common Multiple failing last test
0

#1

I’m having a similar problem, although when I run the code in a browser or in VSCode, I get 6056820 as the answer, which is correct. Every test but the last one passes. Here’s my code:

function smallestCommons(arr) {
    let a = Math.min(...arr), b = Math.max(...arr), test = true;
    for (let i = 1; ; i++) {
        if ((i % a == 0) && (i % b == 0)) {
            for (let j = a; j <= b; j++) {
                if (i % j == 0) test = true;
                else {
                    test = false;
                    break;
                }
            }
            if (test)   return i;
        }
    }
}

Smallest Common Multiple - stuck
#2

I moved your question to a new topic. Because your question related only to your code and you were not requesting clarification about a post in another thread or replying to give advice/feedback to another thread, your question should have it’s own topic.

In the future, please click the Ask for Help button located on the challenge, so that your code and the challenge url are automatically populated to the new topic.

OK, to answer you question, your current algorithm is not fast enough to bypass the test suite’s infinite loop protection feature. The test thinks your solution has caused an infinite loop, even though the true reason is because your algorithm is not efficient enough to pass the last test.

See if you can think of a way to make it faster.