Smallest Common Multiple - Works in browser console but not in FCC tests

Tell us what’s happening:

When I run this in my browser’s JS console, it checks out. However, the FreeCodeCamp tests don’t seem to work. I think I’m losing my mind.



Your code so far

function checkNum(target,factors) {
  var everythingChecksOut = true;
  for (var i = 0; i < factors.length; i++) {
    everythingChecksOut = everythingChecksOut && target % factors[i] == 0;
  return everythingChecksOut;
function getArrayRange(arr) {
  var min = Math.min(...arr);
  var max = Math.max(...arr);
  var newarr = [];
  for (var i = min; i <= max; i++) {
  return newarr;
function smallestCommons(arr) {
  arr = getArrayRange(arr);
  var i = 0;
  var matchFound = false;
  while (!matchFound) {
    matchFound = matchFound || checkNum(i,arr);
  return i;


Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36.

Link to the challenge:

When it fails the last few tests (especially if it works elsewhere) it’s because your algorithm isn’t efficient enough. The FCC test has a timeout on it. See if you can find ways to make it more efficient.

1 Like