Smallest common multiple help

function smallestCommons(arr){
    arr.sort((a,b)=>a-b);
    let x =Math.abs(arr[0]);
    let y=Math.abs(arr[1]);
    let mainArr  = [];
    for(let  i = x;i<=y;i++){
        mainArr.push(i);
    };

    function gcd(a,b){
        if(b===0){
            return a;
        }else{
           return gcd(b,a%b); 
        }
    }
    let mainGcd = gcd(x,y);
    let result =  ((x*y)/mainGcd);
    while(true){
        if(mainArr.every((value)=>result%value===0)){
            return result;
        }else{
            result++;
        }
    }
    
};

So, This function take an array which have two number. I need to find their smallest common multiple number number. Also the number the number should be divisible by all number between those two number. This function work pretty well on my browser console like

if I pass smallestCommons([2,10])
it's return 2520

but I don’t understand why last problem didn’t pass. which is

smallestCommons([23,18])

well I run this problem on my browser console it show me correct answer which is 6056820. But This don’t pass in freecodecamp site. It’s show me a brown cross sign. Please someone tell me is there any issue in my code?

Yeah, same thing happened to me when I was working on this problem. I also had the correct answer but it wouldn’t pass the last test. My understanding is FCC protects against infinite loops so if the loop length gets too long like it would for [23, 18] then it just stops at some point, even if it would eventually reach the correct answer.

well i think I just found the answer to correct this issue. in while loop add biggest number in array with result.

function smallestCommons(arr){
    arr.sort((a,b)=>a-b);
    let x =Math.abs(arr[0]);
    let y=Math.abs(arr[1]);
    let mainArr  = [];
    for(let  i = x;i<=y;i++){
        mainArr.push(i);
    };

    function gcd(a,b){
        if(b===0){
            return a;
        }else{
           return gcd(b,a%b); 
        }
    }
    let mainGcd = gcd(x,y);
    let result =  ((x*y)/mainGcd);
    while(true){
        if(mainArr.every((value)=>result%value===0)){
            return result;
        }else{
            result+=y;
        }
    }
    
};

and I don’t know why but It worked