Smallest Common Multiple. I can not pass the last two checks

Hi! Help me, please!
I do not understand why when checking my code, the first three cases are executed correctly, and the last two cases are executed incorrectly?

case 1: smallestCommons([1, 5]) should return a number.
case 2: smallestCommons([1, 5]) should return 60.
case 3: smallestCommons([5, 1]) should return 60.
case 4: smallestCommons([1, 13]) should return 360360.
case 5: smallestCommons([23, 18]) should return 6056820.

My code:

<p>
function smallestCommons(arr) {
  var newArr = [];
  
  arr.sort (function (a,b) {
    return b-a;
  });
  
  var min = arr[1];
  var max = arr[0];
  
  for (var i=max; i>=min; i--) {
    newArr.push (i);
  }

  
  var i = max;
  var result;
  console.log(newArr);
 
    out:
    for (var j=0; j<newArr.length; j++) {
      var flag = true;
      while (flag) {
        if (i % newArr[j] === 0) {
          flag = false;
        }
        i++;
      }
      result = i;
      
      if (j == (newArr.length-1)) {
        for (var k=0; k<newArr.length; k++) {
        if (result % newArr[k] !== 0) {
          j=0;
          continue out;
          }
        }
      } else {
      continue out; 
      }
    } 
  
  return result;
}
</p>

I’ve edited your post for readability. When you enter a code block into the forum, remember to precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

markdown_Forums