Smallest Common Multiple - I can't make the last test work :(

Smallest Common Multiple - I can't make the last test work :(
0

#1

Tell us what’s happening:
Hi everyone
I’m really going crazy with this smallest multiplier challenge. I’m almost there, it’s now working for all tests except the last one : smallestCommons([23,18]). Does someone have an idea why and where the problem is with my code ?

Your code so far

function smallestCommons(arr) {
  var max = Math.max(arr[0], arr[1]);
  var min = Math.min(arr[0], arr[1]);
  var fullArray = [];
  
  for(var i=max; i>=min; i--){
   fullArray.push(i);
  }
 
  var i = 0;
  var SCM = fullArray[0];
  var multiplied = 1;
  
  do{
    multiplied = SCM * fullArray[0];
    
    for(i=1; i<fullArray.length; i++){
      if(multiplied % fullArray[i] !== 0){
        SCM += fullArray[0];
        break;
      }
    }
  }
  while(i<fullArray.length-1);
  
  return SCM;
  
}
smallestCommons([23,18]);

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36.

Link to the challenge:


#2

You are super close to a working solution to pass the tests! :smiley:

Double check your while loop condition.


#3

wow thank you, I feel really stupid now :see_no_evil: I spent so much time on this, I didn’t even see the obvious !!