Freecodecamp: "Smallest Common Multiple" troubles

Created on 6 Feb 2017  Â·  4Comments  Â·  Source: freeCodeCamp/freeCodeCamp


Challenge Name


Smallest Common Multiple

Issue Description


I don't know why my code passed the first four test, but not the last one --smallestCommons([23, 18]).
Due to "检测完毕" in console, it should have tested all numbers from 23 to 78681840. But if it tested number 6056820, it should echo "检测6056820" in console. I'm really confused.

Browser Information


win7, chrome

  • Browser Name, Version:
  • Operating System:
  • Mobile, Desktop, or Tablet:

Your Code

function smallestCommons(arr) {
  function rangeOf(arr1){
    var low,high;
    if(arr1[0]<arr[1]){
      low = arr1[0];
      high = arr1[1];
    }else{
      low = arr1[1];
      high = arr1[0];
    }
    var result = [];
    for(var i = low;i<=high;i++){
      result.push(i);
    }
    return result;
  }
  function productOfArr(arr){
    var result = 1;
    for(var i = 0;i<arr.length;i++){
      result *= arr[i];
    }
    return result;
  }
  function isMultipleOfArr(number,array){
    for(var i = 0;i<array.length;i++){
      if(number%array[i] !==0){
        return false;
      }
    }
    return true;
  }
  var betArr = rangeOf(arr);
  var max = productOfArr(betArr);
  var min = Math.max(arr[0],arr[1]);
  console.log("betArr: ");
  console.log(betArr);
  console.log("min: "+min+" max: "+max);

  for(var i = min;i<=max;i++){
    if(i == 6056820){
      console.log("检测6056820");
      console.log(isMultipleOfArr(i,betArr));
    }
    if(isMultipleOfArr(i,betArr)){
      console.log("arr: ");
      console.log(arr);
      console.log("i: "+i);
      return i;
    }
  }
  console.log("检测完毕");
//   return max;
}



Screenshot

Most helpful comment

I had issue with the last test.
Later discovered that it is due to infinite loop protection enabled in browser.
Add // noprotect on the first line of your code to pass the test.

All 4 comments

@stskyblade Can you please help us with that challenge link? Could be a Unicode issue.

Please clarify with information as requested. Some screenshots might help as well. Closing for now, we can re-open this when you are ready.

I had issue with the last test.
Later discovered that it is due to infinite loop protection enabled in browser.
Add // noprotect on the first line of your code to pass the test.

@Jez55 Thank you so much. I knew my code was right. thank you so much

Was this page helpful?
0 / 5 - 0 ratings