 Tell us what’s happening:
Hi All,
I can get this to pass all tests except for the last one, can someone please help!

``````
function smallestCommons(arr) {
arr.sort((a,b) => a-b);
var indicator = false;
var commonMulti = arr;

do {
indicator = true;
for (var i = arr; i <=arr; i++){
if(commonMulti % i != 0){
commonMulti++
indicator = false
}
}
} while (!indicator)

return commonMulti

}

console.log(smallestCommons([23,18]));

``````

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

Hey @Hobbo ,
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.

2 Likes

Let

SCM(a, b) = Smallest Common Multiple
GCD(a, b) = Greatest Common Divisor

We know that

a * b = SCM(a, b) * GCD(a, b) =>
SCM(a, b) = a * b / GCD(a, b)

GCD can be computed in a very efficient way using Euclid’s algorithm: https://en.wikipedia.org/wiki/Euclidean_algorithm#Implementations