Smallest Common Multiple: Can't pass the last tow cases

Tell us what’s happening:
Why does my code not pass the last two cases? It worked on my own laptop.

Your code so far


function smallestCommons(arr) {
  let mutl = Math.max(...arr);
  let rag = [];
  for(let i=Math.min(...arr); i<=Math.max(...arr); i++) {
    rag.push(i);
  }
  while(1) {
    if(rag.map((e)=>(mutl%e === 0)).every((a)=>(a === true))) {
      break;
    }
    mutl +=1;
  }
  return mutl;
}

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

infinite loop protection. You are checing numbers one at a time, and for each number you are checking if it is a multiple… find an other way, this brute forcing require too much processing power when the Smallest Common Multiple is so high (see from the tests where you should do it)

There are various ways in which you can solve this one, but it has to have enough efficiency to not trigger the infinite loop protection

1 Like