Https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple/

Hi Team,

I have written below code to pass the ** Intermediate Algorithm Scripting: Smallest Common Multiple** in the javascript section. This code is not passing the last 2 test cases ([1,13] and [23,18]) for that problem. But when I have tested my code in Chrome console it is returning me the right result.
Can anyone tell me what is the issue with my code.

function smallestCommons(arr) {
  let max = arr[0] > arr[1] ? arr[0] : arr[1];
  let min = max == arr[1] ? arr[0] : arr[1];
  let diff = max - min;
  let end = true;
  for(var i = max + 1; end === true; i++) {
    var count = 0;
    for(var j = min; j <= max; j++) {
      if(i % j === 0) {
        count += 1;
      }
    }
    if(count == diff + 1) {
      end = false;
      return i;
    }
  }
}

smallestCommons([1,13]);

Thanks & Regards,
Shashank

the freecodecamp editor has a infinite loop protection. Your code is taking too much time to execute.

YYou are checking numbers one by one, that means that for the last test your code needs at least 6 millions iterations - that’s too much, you need a different algorithm