Smallest Common Multiple fcc

Smallest Common Multiple fcc
0

#1

My code is running fine and all the test cases. But it feel it is not appropriate somehow. Can anyone explain if there is something wrong with it?

Your code so far


function smallestCommons(arr) {
arr=arr.sort(function(a,b){
  return a>b;
});

let myarr=[],newarr;
for(let i=1;i<999999;i++){
  let num=arr[1]*i;
  if(num%arr[0]===0){
    for(let j=arr[0]+1;j<arr[1];j++){
      if(num%j==0){
        myarr.push(j);
    }

    }
    if(myarr.length!==arr[1]-arr[0]-1){
      myarr.splice(0,myarr.length);
    }else{return num;}
  }
}
}

smallestCommons([1,5]);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36.

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


#2

I guess you were trying to create an infinite loop here? Have you considered using a while loop?