# Problem 5: Smallest multiplePassed

Tell us what’s happening:
Describe your issue in detail here.

I am trying to solve Euler problem 5, and the code works locally.
It solves the challenge locally but when trying to submit my solution to fcc the last test breaks because of a potential infinite loop.

locally the last test runs in about 1 to 4 seconds.

``````function smallestMult(n) {

let numbers = [];
let i = 1;
outerloop: while (numbers.length <= n) {

for (let j = 1; j <= n; j++) {

if(numbers.length == n){
break outerloop;
}

if (i % j == 0 && i != j) {
numbers.push(i)
} else {
i++
numbers = []
}
}

}
console.log(numbers[0])
return numbers[0]
}

``````

User Agent is: Chrome
Challenge: Problem 5: Smallest multiple

From my experience anything taking longer than one second for single case may have problems with passing on site.

If you want small tip, without making many changes - consider what can be done to ensure each checked number is divisible by the largest required divisor in a given case.

2 Likes

consider what can be done to ensure each checked number is divisible by the largest required divisor in a given case.

I don’t really understand what you mean by this. Can you give me an explanation without spoiling me the answer?

I’ve tried to write explanation, but I couldn’t be sure it wasn’t spoiling something. Instead I’ll try to formulate it as a bit expanded questions.

First thing - what in each test case is the largest divisor, by which number have to be divisible?
How it can be ensured each candidate number is divisible by that largest divisor?

I think I get what you mean thanks.

One simple change and it runs like a charm thanks @sanity

1 Like

Now that your code runs, this is a problem where looking at how others have solved it can be very helpful.

I could but in project Eulers philosophy and rules they discourage sharing your solution to the problem.