# Smallest Common Multiple

``````function smallestCommons(arr) {

let multiple = [];

for (let i = 0; i < arr.length; i++) {
if (arr.range(i,i + 1) % 2  == 0) {
multiple % arr.range(i,i + 1) === 0;
}
}
return multiple;
}

smallestCommons([1,5]);
``````

My head is all over the place with this one. I thought I could use the range method in this way but I am doing a lot of things wrong. Can someone help me out?

I would ignore fancy syntax. You only need to express a clear, detailed plan with if and for. Fancy syntax cannot make a plan for you if you donâ€™t have one.

1 Like

Iâ€™d suggest you refactor your code by setting the conditions clear. After setting the condition, donâ€™t forget the empty multiple array. Check string methods i.e Push()
Good luck buddy!

The point of these challenges is to practice understanding a problem and developing solutions.

``````function smallestCommons(arr) {

for (let i = 0; i < arr.length; i++){
// if the two numbers in arr can be evenly divided
if (i % 2 == 0 && (i + 1) % 2 == 0)
// if all the numbers between them can also be evenly divided
// return the first smallest common multiple all these numbers have
}
return arr;
}

smallestCommons([1,5]);
``````

Is this a better straightforward plan? I checked if the numbers in the arr can be evenly divided, but I am having a hard time thinking of a way to check all the numbers in between as well

You still seem pretty allergic to the idea of starting with absolutely zero code, but I would really encourage you to do that.

If you had a piece of paper and a pencil only and are forbidden to write any code at all, how can you describe the process?

You donâ€™t really have a full process described here - more some ideas on things you might need to check?

1 Like
``````function smallestCommons(arr) {

// Check all the multiples of numbers 1-5
// a multiple of a number is basically adding up by that number over and over
// for example 1:[1,2,3,4,5,6,7,8,9...]
// 2: [2,4,6,8,10...]
// 3: [3,6,9,12,15,18,21...]
// 4: [4,8,12,16,20...]
// 5: [5,10,15,20,25,30...]
// if you continued going up, eventually you would realize that 60 is the smallest common multiple for numbers 1-5

return arr;
}

smallestCommons([1,5]);
``````

I really appreciate how blunt and honest you are. I didnâ€™t write any code at all and wrote out the process, is this better?

How would you realize this though?

Computers will need really specific instructions, so our plan needs to be specific.

Because you would see that 60 is the first number that 1,2,3,4, and 5 all have in common. Like 1-3 all have 6 in commonâ€¦but you canâ€™t say thatâ€™s the smallest common multiple because 4 and 5 donâ€™t have 6

How do you â€śseeâ€ť? How do you check for this exactly?

I can see this by looking at the pattern I have made for each number. Or do you mean like how can you see this in terms of code? Maybe by creating a loop with instructions for each number that tells the number to keep adding by itâ€™s own value until all numbers find a number they have in common

What â€śpatternâ€ť?

A computer canâ€™t â€śseeâ€ť a â€śpatternâ€ť unless you say how.

Iâ€™m not talking about code here. Iâ€™m talking about a step by step process. You canâ€™t write code if you donâ€™t have small enough steps.

I think this idea of making a number and testing to see if it works might be easier to write a step by step process for.

The pattern of n+nâ€¦over and over again

What do you mean by making a number?

What could it mean? How might that idea work? How could you use this information here to guess numbers that might be the smallest common multiple

The smallest common multiple is going to be divisible by all of those numbers (2,3,4,5). We can guess the right number will have a remainder of 0 when divided by (2,3,4,5).

Iâ€™m not sure weâ€™re understanding each other?