Smallest Common Multiple code not working

Tell us what’s happening:
does this code work for this problem. its saying that it does not for smallestCommons([23, 18]) but im pretty sure it does. can some one help.

Your code so far


function smallestCommons(arr) {
  var range = [];
  var max = Math.max.apply(null,arr);
  var min = Math.min.apply(null,arr);
  var cnt=0;
  for (var k=min;k<=max;k++){
    range.push(k);
  }
  for(var i=max;i<Number.MAX_VALUE;i+=max){
    for(var j=0;j<range.length;j++){
      if(i%range[j]==0){
        cnt++
      }
      
    }
    if(cnt==range.length){
      return i;
    }
    cnt=0;
    
  }
  
}
smallestCommons([23, 18]);

Your browser information:

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

Link to the challenge:

you are probably triggering the infinite loop protection, you will need to write a faster function

1 Like

yea it was that. Thank you very much