Freecodecamp showing wrong infinite loop error

Freecodecamp showing wrong infinite loop error

function smallestCommons(arr) {
  var arr1=[];
  arr.sort(function(a,b){//sorting argument array
    return a-b;
  for(var i=arr[0];i<=arr[1];i++){//getting a range between the two given numbers of array i.e[1,5]=[1,2,3,4,5]
  var j=1;
  var result=[];
  var num;
  while(result.length==0){//keep looping until we dont get LCM in result array
    num=arr1[0]*j;//Getting the number in num which is to be checked as LCM of all numbers of arr1 
    for(var k=0;k<arr1.length;k++){//checking if num is LCM for all arr1 numbers
      if(num%arr1[k]!=0){//break the loop if num is not fully devided by any arr1 numbers
      if(num%arr1[k]==0){//iteratively checking if num is LCM of all arr1 numbers
        if(k<arr1.length-1){//only continue to check next arr1 number if it is not last
        result.push(num);//push the LCM in result if loop never breaks
    j++; //if loop breaks increment j to get next number in num which is to be checked
 return result[0];


Program is to find the smallest common multiple of the provided parameters that can be evenly divided by both, as well as by all sequential numbers in the range between these parameters. My code runs great every where including mozilla developer tool and sublimetext 3 for all test cases. But in freecodecamp results it is showing infinite loop for [1,13] case at line 14 i.e “num=arr1[0]*j”. I couldnt figure out the problem kindly help me out.


check for which values it breaks, now that you know at which line it happens.

 1*x = x


It is only showing infinite loop error in freecodecamp compiler at line 14.Except there it is working fully fine. If you go to this challenge and try for example [1,12] it is showing result. but as soo u exceed from 12 like [1,13] it shows infinite loop. it is doing similar thing for [23,18]. Works for [23,19]. But showing infinite loop error at [23,18] Again note that it is showing this kinda error only in freecodecamp compiler,every where else it is working all fine. [23,18] and [1,13] are last 2 cases for this intermediate algo scripting challenge.


I can’t duplicate your error. (Is it an “error” or a “warning”?)

I’m suspecting that it is just taking a long time. I think you can put //noprotect at the top of the code to disable infinite loop protection. WARNING: This can be a dangerous thing to do. If you do have an infinite loop (or program that will take 3.78 years to complete) then you will lock up your browser. There were a few challenges where I had to do this, but if I looked harder, sometimes I found a faster algorithm.