JS: Smallest Common Multiple

Tell us what’s happening:

I don’t understand why this code won’t pass the last challenge. Is there a limit to the number of loops on FCC? It works on VS Code.

Your code so far


function smallestCommons(arr) {

  arr.sort((a,b) =>  a - b);

  let numsInBetween = [];

  for (let i = arr[0]; i <= arr[1]; i++) {
    numsInBetween.push(i);
  }

  console.log(numsInBetween);

  let smallestMult = arr[1];
  let checker = true;
  for (let counter = 1; checker = true; counter++) {
    smallestMult *= counter;
    for (let i = 0; i < numsInBetween.length; i++) {
      if(smallestMult % numsInBetween[i] == 0) {
        if(numsInBetween[i] == numsInBetween[numsInBetween.length - 1]) {
          checker = false;
          console.log(smallestMult + " It is");
          return smallestMult;
          break;
        } else {
          continue;
        }
      } else if(smallestMult % numsInBetween[i] != 0){
        smallestMult = arr[1];
        break;
      }
    }
  }

  console.log(arr);
  console.log(numsInBetween);
}


// smallestCommons([1,5]);
// smallestCommons([1, 13]);
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/72.0.3626.121 Safari/537.36.

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

Yes, there is an infinite loop protection.

So how do I go around this?

I’ll give you a hint:
If you’re trying to figure out common multiple of, say 5 and 7, do you really need to check every number? Like 8, 9? Or you can just skip to 10?