Implement a Range-Based LCM Calculator - Implement a Range-Based LCM Calculator

Tell us what’s happening:

It is giving the right answers but failing all the tests but the first one, if you could help me figure out why that would be great! thanks!

Your code so far


const smallestCommons = (a, b) => {
  let max = Math.max(a, b);
  let min = Math.min(a, b);
  let array = [];
  
 
for(let i = min; i <= max; i++){
    array.push(i);
};
 return array.reduce((a, b) => {
     while (true) {
 if (max % a === 0 && max % b === 0) {
 return max;
  }
 max++
  }
 });

};

console.log(smallestCommons(23, 18));


Your browser information:

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

Challenge Information:

Implement a Range-Based LCM Calculator - Implement a Range-Based LCM Calculator

Review user story #1

  1. You should have a smallestCommons function that accepts an array of two numbers as an argument.

Did you test the input for test 2?

  • Failed: 2. smallestCommons([1, 5]) should return a number.
console.log(smallestCommons([1, 5]));
>> TypeError: reduce of empty array with no initial value

Haha that was it! thanks!!! : )