Smallest Common Multiple vs. Least Common Multiple

Can someone explain the difference because what I’m noticing is that the test answers aren’t matching this Least Common Multiple Calculator

My code so far (but it looks like I was solving for the wrong problem)

/* 
Find the greatest common divisor of two numbers
Using the Euclidean algorithm https://youtu.be/JUzYl1TYMcU
*/
function gcd(a,b){ 
   if (b > a) { return gcd(b,a);}
   let r = a % b;
  return (r === 0) ? b : gcd(b,r);
}

function lcm(a,b){
  return (a / gcd(a,b)) * b;
}

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.

So we want the LCM for all numbers in a range. Here is a calculator that will let you put in more than 3 numbers.

1 Like

Thak you, with that insight rewritten as.

Array.range= (start, end, step = 1) =>{
    const A = [start];
    while(start + step <=  end){
      A.push(start += step);
     }
    return A;
};

function gcd(a,b){ //Find the greatest common divisor of two numbers
   if (b > a) { return gcd(b,a);} 
   let r = a % b;
  return (r === 0) ? b : gcd(b,r);
}

function lcm(a,b){
  return (a / gcd(a,b)) * b;
}

function smallestCommons(arr) {
  let [start, end] = arr.sort();
  return Array.range(start,end).reduce((a,b)=>{return lcm(a,b);});
}