Smallest Common Multiple strange problem

Tell us what’s happening:

Hello guys. Yesterday, I tried to complete this challenge, but I got to the point, where I couldn’t find an answer. Today I am trying the same, but with same result. The problem is, that my solution works for first four demands on the left (" smallestCommons([1, 5]) should return a number." and so on…), but not the last two. I can’t figure out, why does my solution behave this way. I think it does not do what it’s supposed to, based on program I written. Here is my solution and I kindly ask you to take a look, if you guys can find the problem:

function smallestCommons(arr) {
  arr = arr.sort ((a,b) => a-b);
  var multiple = arr[1];

    for(let i=arr[1]; i>= arr[0]; i--){
      if(multiple%i != 0){

        return multiple;
  return arr;


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0.

Technically your code produce the correct output, however it’s not getting accepted because FCC has an infinite loop protection, and your code stays inside the same loop more that ~500ms.

1 Like

Oh, I see. So I have to figure out how to make faster code. Thank you!

1 Like