# (Smallest Common Multiple challenge) =\> Can my code be better?

**URL:** <https://forum.freecodecamp.org/t/smallest-common-multiple-challenge-can-my-code-be-better/32692>\
**Category:** General\
**Created:** [August 31, 2016, 2:27am UTC](https://forum.freecodecamp.org/t/smallest-common-multiple-challenge-can-my-code-be-better/32692 "2016-08-31T02:27:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lenaggar](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/lenaggar/32/4868_2.png) [@lenaggar](https://forum.freecodecamp.org/u/lenaggar)\
**Post date:** [August 31, 2016, 2:27am UTC](https://forum.freecodecamp.org/t/smallest-common-multiple-challenge-can-my-code-be-better/32692/1 "2016-08-31T02:27:41Z")

</div>

hi campers,  
just solved the Smallest Common Multiple challenge and was just wondering if this code can be more efficient??

```
function smallestCommons(arr) {
  
  // sort the argument's array
  arr.sort((a, b) => a - b);
  
  // declare an array to store all sequential numbers
  // in the range between the given parameters 
  var seqArr = [];
  
  // a loop to construct the declared array with the values
  for(var i = arr[0] + 1; i < arr[1]; i++) {
    seqArr.push(i);
  }
  
  // a loop that iterates starting from the largest number
  // of the given two to check for the smallest common multiple
  for(i = 1; i > -1; i++) {
    var x = arr[1] * i;
    
    // a check for the smallest common multiple considering only
    // the two given parameters
    if((x % arr[0]) == 0) {
      
      // another check in case of true smallest common multiple
      // but this time to check with the all sequential numbers in the range
      if(seqArr.filter((val) => x % val > 0)[0] === undefined) {
        return x;
      }
    }
  }
}

```

thanks in advance 🙂

---

<div class="post-metadata">

**Author:** ![jwilkins.oboe](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jwilkins.oboe/32/179497_2.png) [@jwilkins.oboe](https://forum.freecodecamp.org/u/jwilkins.oboe)\
**Post date:** [January 16, 2021, 5:29am UTC](https://forum.freecodecamp.org/t/smallest-common-multiple-challenge-can-my-code-be-better/32692/2 "2021-01-16T05:29:16Z")

</div>

Closed on January 16, 2021, 5:29am UTC


