Smallest Common Multiple Algorithm - Confused, Code Works but Not Given the Radical Badical Green Light

Smallest Common Multiple Algorithm - Confused, Code Works but Not Given the Radical Badical Green Light
0

#1

So my code passes the first 4 out of 5 test case no problem. I realized it works for the 5th as well but I add to add //noprotect to the top of the page. Although when I add that line it says the last test case is good but not the first four which is false! It even shows the correct value when I test for [23, 18] but it says it’s wrong! (seen in the screenshots) I’ll add screenshots and my code that will better explain the situation.

// noprotect
//find smallest common multiple of all parameters
function divisibleByAll(num) {
  var smallestCommonMultiple = num;
  for (var i = 0; i < parameters.length; i++) {
    if (smallestCommonMultiple % parameters[i] !== 0) return false;
  }  
  return true;
}

function smallestCommons(arr) {
  var isSmallestCommonMultiple = false;
 
  //put the two numbers in order
  arr.sort(function(a, b) {
  return a - b;
  });
  //make an array with the two numbers and all number inbetween them 
  for (var i = arr[0]; i <= arr[1]; i++) { 
      parameters.push(i);
    }
 
  var number = arr[1] + 1;
  
  while (!divisibleByAll(number)) {   
    number++;
  }   
  return number;
}
var parameters = [];

smallestCommons([1,5]);


Thank you in advance for any light you can shed!
-Todd


#2

When I test your included code above, the last case does not return the correct result.


#3

Thank you for taking the time to help out! It ended up being the global variable I had declared. Once I passed passed parameters instead of declaring it globally I passed all the tests!