Smallest common multple

Smallest common multple
0.0 0


Hi there,

I am struggling hard with this challenge, after cruising through all the previous challenges, the past 3 have been really challenging to the point where I am doubting about what I thought I know…

I tried to simplify this challenge by solving it by pieces. After finding a math formula to find the lcm ( LCM(a,b) = (a*b)/GCD(a,b) ), i succeeded to make it work but only for 2 numbers.

function smallestCommons(arr) {

function remainder(a, b){
  if (a === 0){
    return b;

  while (b !== 0){
     if (a > b)
     a = a - b;
     b = b - a;
  return a;
var cgd = remainder(arr[0], arr[1]);
var lcm = (arr[0]*arr[1])/cgd;
return lcm;
console.log(smallestCommons([12, 30]));

After doing that I thought that i will just have to implement a loop somehow to go through the range and pass every number, but I can’t figure how to do so. I keep looking at the solution of other people and can hardly understand them.

I am clearly lacking a great dose of logic on this one and I could use some help on how to get to the next step!

Thank you!


This isn’t your answer, but b = b - a; can be simplified ti b-=a

These challenges are very hard, but the knowledge gained is useful.


Hi John,

Thanks for the tip! yes those are getting harder, even make me question if I will be able to complete all of them! it’s not even the advanced one.

Thanks for your help.


Me and a lot of people i have seen have never done advanced. Intermediate and basic is what is required. I feel as there just not interesting enough to spend 5 hours per on. You could write a decent amount of code for your projects in that time.


If you’re still struggling with this one, here’s a non-elegant way to complete this: you could brute-force it by having a loop check if a particular number is divisible by all the numbers given. If it isn’t, then increment that number by one and try again.



Thanks for the reply. I left this one unfinished, as I was losing my mind too much! I think this could be solved using a recursive function. What do you think?


You are way closer than you think. I will drop you the following hint and leave the rest to up to you.
You already have the base case of this recursive formula namely the lcm of just two numbers.


Or you could just follow a tutorial:

I feel like this challenge was too hard.