Smallest Common Multiple - bug?

Tell us what’s happening:

I have finished my code for the challenge and all the tests work perfectly on jsfiddle. When I copy the code to freecodecamp, the numbers of two last test aren’t returned. Can someone help me :)?

Your code so far


function smallestCommons(arr) {
  let small = Math.min(...arr);
  let big = Math.max(...arr);

  let proov = [];
  for (var i = small; i <= big; i++) {
    proov.push(i);
  }

  console.log(proov);

  for (var g = 1;; g++) {
    let number;
    for (var j = 0; j < proov.length; j++) {
      if (g % proov[j] == 0) {
        if (j == proov.length-1) {
          number = g;
          console.log(number);
          return number;
        }
      } else {
        break;
      }
    }
  }
}


smallestCommons([1, 13]);

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple

Hey @snjegu,
Your code needs to be efficient to pass the challenge.
Your code is activating the FCC’s infinite loop protection.

So, try to make your code a little efficient.

All the best.

1 Like