 # Struggles with Smallest Common Multiple Algorithm

Hey, I’ve been struggling with the smallest common multiple algorithm.

I understand the problem this way.

1. I need to find the min and max numbers between the two of the items in the arr.
2. Next, I need to create an array and put all of the numbers in the range between the min and max numbers there, including both of them.
3. I need to create a loop which increments a number until it finds the one which’s remainder is 0 to all of the numbers in the array.

I know how to do the first two steps, but I am stuck at the last one.

I don’t know how to create a loop which will increment a number from 0 till it finds the one which’s remainder is 0 when it’s divided by each of the numbers in the array.

Any help and tips how to think would be much appreciated.

My code so far:

``````
function smallestCommons(arr) {
let minNum = Math.min(...arr);
let maxNum = Math.max(...arr);
let mySeq = [];
for(let i = minNum; i <= maxNum; i++){
mySeq.push(i);
}
// stuck here
}
``````

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

I guess I may not be understanding the entire question. Is this a problem from the curriculum? I would maybe try a do/while loop:

``````do {

minNum /= 2

} while (minNum > 0);
``````
1 Like

Hey, yeah, it’s the one from the Intermediate Algorithm Scripting Section.

It is supposed to find the smallest common multiple of the provided parameters that can be evenly divided by both of them plus the ones in between them.

The array always consists of two numbers which can be not in a numerical order.

For example. A value of [1, 3] would return 6, or [1, 5] would be 60.

Did you get a solution? I thought this was an interesting one.