Smallest Common Multiple--what's the problem?

Tell us what’s happening:
When I tried the function which I created so far, it worked correct as far as arr[1] is less than 13. However, when I made arr[0] equal to 1 and arr[1] equal to 13, the output was incorrect, and what is very strange was that every time when I refreshed it, it came up a different result. Just can’t figure out the reason. NEED HELP thanks…

Your code so far


function smallestCommons(arr) {
  var fullArr = [];
  if(arr[0] > arr[1]) {
    arr.reverse();
  }
  for(let i = arr[0]; i <= arr[1]; i++) {
    fullArr.push(i);
  }
  var cm = 1;
  while(fullArr.map(a => cm % a).reduce((a, b) => a + b) !== 0) {
    cm++;
  }
  return cm;
}


console.log(smallestCommons([1, 17]));

Your browser information:

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

Link to the challenge:

it seems that your code is taking too much to run and is triggering the infinite loop protection, which is stopping your code prematurely
you will need to refactor your code so that it will need less to run

Hi, it’s some update. Today I have tried my code at other place, and it worked well. All the outputs are correct even the larger number is bigger than 13. I don’t know why it’s not working on the freecodecamp website. It’s very funny…

Anyway, thank you for your reply again.