Smallest Common Multiple calculation problem

Tell us what’s happening:
SO, everything is working fine, except for the last test, giving a wrong answer.
I tested the code somewhere else, and it works fine, just wanna know where the problem is coming from and why is smallestCommons([23,18]) giving me 610722 instead of 6056820.

thanks

Your code so far


function smallestCommons(arr) {
  let min = Math.min.apply(null, arr);
  let max = Math.max.apply(null, arr);

  
  let array = Array.from({length: max + 1}, (v, k) => k).slice(min)
  console.log(array)


  return array.reduce((x,y) => {
    console.log('x = ' + x + ' y = ' + y)
    let i = (x<y)?y:x;
    while ( i%x != 0 || i%y != 0) i++
    console.log("LCM = " + i)
    return i;
 });
}

console.log(smallestCommons([23,18])) 

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:65.0) Gecko/20100101 Firefox/65.0.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple

To protect campers from accidentally crashing their browsers with infinite loops, FCC impliments a timout in their challenges. If your code is inefficient, it can take longer than the timeout allows even if you don’t actually have an infinite loop or inifinite recursion. In your case, simply removing the console.log statements inside your function may be enough to let your code run more quickly.

thanks for the answer, it’s the while loop that’s taking too much time when the numbers are too big, even without the logs, it’s the same.