# Help with Smallest common multiple

**URL:** <https://forum.freecodecamp.org/t/help-with-smallest-common-multiple/170625>\
**Category:** General\
**Created:** [January 24, 2018, 10:28am UTC](https://forum.freecodecamp.org/t/help-with-smallest-common-multiple/170625 "2018-01-24T10:28:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jyosiva](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@Jyosiva](https://forum.freecodecamp.org/u/Jyosiva)\
**Post date:** [January 24, 2018, 10:28am UTC](https://forum.freecodecamp.org/t/help-with-smallest-common-multiple/170625/1 "2018-01-24T10:28:34Z")

</div>

```auto
function smallestCommons(arr) {
  var val;
  
  arr = arr.sort(function(a, b){
    return a - b;
  });
  
  
  
  for(var num=1;;num++)
    {
  val=lcm(num,arr[0],arr[1]);
      if(val===true)
        break;
    }
  
  function lcm(n,a,b)
  {
  for(var i=a;i<=b;i++)
    {
      if(n%i!==0)
        return false;
                     
    }
  return true;
  }

```

I first sorted the array smallest to largest, then kept an infinite loop passing no’s from 1 to n to find the number ie.lcm of array of no’s,which will stop once the number is found, then a function to find lcm of all no’s between that array. but its not working for 1,13 and 18,23 while the logic is correct… Thanks in advance.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 17, 2021, 8:29pm UTC](https://forum.freecodecamp.org/t/help-with-smallest-common-multiple/170625/2 "2021-01-17T20:29:32Z")

</div>

Closed on January 17, 2021, 8:29pm UTC


