Error on "Smallest Common Multiple" e

My solution to this problem is this:

function smallestCommons(arr) {
  let start = Math.min(...arr);
  let end = Math.max(...arr);
  let number = end;
  let stop = false;
  console.log("start", start, "end", end, "number", number);

    let valid = true;
    for(let i=start; valid && (i <= end); i++){
      valid = (number % i === 0);
      stop = true;
  console.log("Arr", arr, "Number:", number);
  return number;

I tried out directly in the browser and it is working correctly but when I run on FCC it fails for [1, 13] and [23,18].

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.


It appears your solution is not efficient enough, which means it is taking longer than FCC expects. When this happens, a built-in infinite loop protection features stops your code from continuing. You do not have an infinite loop, but the test thinks you do. To pass the challenge, you will need to think about how you could make your solution faster. All of the FCC challenges can be solved without triggering the infinite loop protection feature, but some algorithms are more efficient than others.