Smallest Common Multiple My code works perfectly at console but doesn't pass the tests, what's the problem?

My question still stands, the guy runs O(n2)

The guy runs a loop. inside. a. whole. loop.

It’s a loop inside a loop, it’s like when the loop finishes, the first loop re-runs again…etc

If the browser doesn’t ignore that but ignore my code then I have nothing to say. Yeah I admit that my code runs many resources since it increases by Math.max() and so it can be a problem but it’s definitely not as much as the above code and I believe that I created more complex functions than that but they still work. So I guess that freecodecamp’s environment is different. I mean honestly, if the browser ignore this kind of loops then I think that the heavy web apps by companies wouldn’t work, right?

Again, I’m not trying to say that you’re wrong but there’s definitely more to it.

It’s not about too much for, what a particular math stuff like big o you mentioned pal. This is becasue of total operations. Even that suggested code may not pass a test for [32,54] for instance, becasue of too much works.

This is more like you want multiple 1629 to 3910. the easy way is 1629*3910, but the hard way is adding 1629 3910 times.

Great, so you admitted this part.

FCC test is run locally, this is your context. check my previous answer. I’m not sure, but maybe each page has its own js script. This is also not a constant value to assign for each page ot globally. I tested your code, sometimes it stopped so soon, sometimes long(more iteration)

I believe no any big company may come with that much process as your code does. Please note browser may decide to break a code based on ops/second for instance. So having a heavy page, doesn’t mean it’s heavy work! Most of the process may be taken for page rendering.
Please note we are talking about client-web and JS, you think like a native application on it.

C’mon comrade! I’m not sad or it’s not about it dude, take it easy. We are here to try figure it out, I cannot say I’m the right one here, but hope making my statements true.

Keep going on great work comrade, happy coding.

Finally, I rewrote the algorithm myself after 6 hours from thinking to be much more light and easier, it passes the tests now, this is my solution:

function GCD(a,b) {
  if(a === 0) {
    return b;
  }
  return GCD(b%a,a);
}
function difference(array) {
  for(var i = Math.min(...array)+1;i < Math.max(...array);i++) {
    array.push(i);
  }    
  array.sort((a,b) => a - b);
}
function smallestCommons(arr) {
  difference(arr);
  var a = arr[arr.length-1];
  var b = arr[arr.length-2];
  var LCM = a*b/GCD(a,b);
  while(true) {
  var index = arr.findIndex(element => LCM % element !== 0);
  if(index === -1) {return LCM}
  LCM *= arr[index] / GCD(LCM,arr[index]);
  }
}


smallestCommons([1,5]);

Thanks for everyone. It seems that freecodecamp has a feature to not pass any test if it passed over the required time. Finally I finished this challenge! Sigh.

Well done, great progress. This is why I like passionate people like you code like boss.

keep going on great work, happy programming.

Hahaha thank you.

I would have probably treated this problem as a bug and ignored the whole challenge if not for you two. Thank you all.