Smallest Common Multiple question about my code

can you help me understand how this is working ? I cant seem to break down how it’s working. Thank you. this is the specific part const gcd =(a,b) => a ? gcd(b % a, a) : b;
const lcm =(a,b) => a * b /gcd(a,b);
return myArr.reduce(lcm);

   **Your code so far**
function smallestCommons(arr) {
 let myArr = [];
 let min = arr.reduce((a,b) => Math.min(a,b))
 let max =arr.reduce((c,d) => Math.max(c,d))
for(let i=min; i<=max; i++){
  myArr
  .push(i)
  
   
  } 
 const gcd =(a,b) => a ? gcd(b % a, a) : b;
 const lcm =(a,b) => a * b /gcd(a,b);
 return myArr.reduce(lcm);
}

console.log(smallestCommons([1, 5]));
   **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36

Challenge: Smallest Common Multiple

Link to the challenge:

This is very similar to the provided solutions. I’d look at this note:

This solution uses formulae and algorithms for the Greatest Common Divisor and Least Common Multiple off of Wikipedia to compactly and quickly compute the Smallest Common Multiple.

Specifically I’d go look up the stuff mentioned on Wikipedia.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.