Smallest Common Multiple - Inconsistent results

Smallest Common Multiple - Inconsistent results
0.0 0

function smallestCommons(arr) {
    var temp = arr[0];
    arr[0] = arr[1];
    arr[1] = temp;
  var match = 1;
  var found = false;
  var c = 0;
     found = true;  
      c = 0;
  return match;

When I run this the first 3 checks pass but the other two don’t, while showing different values for match each time. Why does this happen? What am I doing wrong?



I think your code works but it might be timing out. If your code runs long FCC just assumes you have an endless loop and halts execution. I ran your code in developer console and it ran to completion with correct answers.

You can bypass that endless loop protection in FCC if you are confident in the code. (There is also solution at link showing what to do if you have an endless loop that prevents you from returning to the problem page.)

That said, if your code is running that long it may need some tweaking.

Good luck. That’s a hard one.


Thanks! I defined match as arr[1] and then I incremented it by arr[1] so that it converges faster.