Smallest Common Multiple @Pra_Bhu

Tell us what’s happening:
Hi Guys,
I have been facing the issue for past few code challenges.
“The code runs fine in my VSCode IDE but it always fails in the last test case on the freecodecamp site. Similar issue happened in SumOfAllPrimes challenge. my VSCode says the exact output as per the test cases but the same code fails here for the last test case(which is maximum range)”

Your code so far


function smallestCommons(array) {
    let arr=[];
    array.sort(function(a, b) {
        return b - a;
    });
    for(let j=array[0]; j>=array[1] ; j--){
        arr.push(j);
    }
    let i=1;
    let product =0;
    let buffer=[];
    do{
        product = arr[0]*i;
        buffer=arr.map(
            curr => product%curr==0 ? true : false
        );
        i++;
    }while(!buffer.every(curr => curr == true));
    console.log(product);
    return product;
}

smallestCommons([1,5]);

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:65.0) Gecko/20100101 Firefox/65.0.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple/

The tests are also designed with performance in mind.

If your algorithm takes too long to pass a test, it will fail it.

Ohhh!!!
So can you please help me out here!!!
What do you suggest?
How can I test the performance?

There are many resources out there on how to approach this problem. You can search for least common multiple.

Here is one of them.