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

(Smallest Common Multiple challenge) => Can my code be better?
0.0 0

#1

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 :slight_smile: