Smallest Common Multiple - Did I 'break' this challenge?

I believe the code I have should technically pass this challenge. However, it uses a while loop which stops at a very large i and as a result, it is not passing the following tests:

smallestCommons([1, 13]) should return 360360.

smallestCommons([23, 18]) should return 6056820.


function smallestCommons(arr) {

    arr.sort((a,b) => a-b)

  let i = 1
  let min = arr[0]
  let max = arr[1]
  let minMultiples = []
  let maxMultiples = []
  let commonMultiples = []
  let numbersBetweenMinMax = []

  for (let n = min ; n<=max ;n++) {
    numbersBetweenMinMax.push(n)
  }

  while ( i < 1000000) {
    minMultiples.push(arr[0]*i)
    maxMultiples.push(arr[1]*i)
    i++
  }

  for ( let j = 0 ; j < minMultiples.length ; j++) {
    if (maxMultiples.indexOf(minMultiples[j]) > -1) {
      commonMultiples.push(minMultiples[j])
    }
  }


  for (let k = 0 ; k<commonMultiples.length ; k++) {
   if (numbersBetweenMinMax.every(n => commonMultiples[k] % n == 0)) {
     return commonMultiples[k]
   }

  }



}


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/73.0.3683.103 Safari/537.36.

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

You are triggering the infinite loop protection which will stop a loop if it is taking too much time

Maybe you need to refactor your code a bit?

Yeah… Any pointers for refactoring without changing the solution approach completely?

do you really need that while loop?

That may have a big cause in triggering the protection.

Can you change your code to not use that while loop?

Or you may need to take a look to math theory to find an algorithm - knowing what a smallest common multiple and how it is mathematically found was useful for me.