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!

I think GPT can help you to solve this issue. That’s an easy task for it.

Don’t use ChatGPT. That’s bad advice.

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?

How might we go about this guessing?

We could only look at the largest number…5. Then once 5 shows us a number that is also divisible by 4,3,2…then we know that is the lowest common multiple. Instead of looking through each numbers sequence

Sorry if I am still not understanding you

How does 5 show us numbers?