Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

220
Views
Finding Smallest Common multiple in the given range of numbers in Java Script

Hi it's my first question here, Find the smallest common multiple of the provided parameters that can be evenly divided by both, as well as by all sequential numbers in the range between these parameters.

The range will be an array of two numbers that will not necessarily be in numerical order.

For example, if given 1 and 3, find the smallest common multiple of both 1 and 3 that is also evenly divisible by all numbers between 1 and 3. The answer here would be 6.

Ive tried the following code but I dont know why its not working...

 function smallestCommons(arr) {
  arr.sort(function(a,b){return a-b});//sorts the array
  /* Prints a sorted Array*/
  let sortArr=[];
  for(let i=arr[0];i<=arr[1];i++){
    sortArr.push(i);
  }

  /*Find Largest Possible LCM*/
  let largeCM=1;
  for(let i=0;i<sortArr.length;i++){
    largeCM*=sortArr[i];
  }

/*Array of multiples of last element of SortArray*/
let newArr=[];
  for(let i=arr[1];i<=largeCM;i+=arr[1]){
    newArr.push(i);
  }

/*Finding the final final possible values*/
  for(let i=arr[0];i<=arr[1];i++){
    for(let j=0;j<newArr.length;j++){
      if(newArr[j]%i !=0){
        newArr.splice(j,1);
      }
    }
  }

/*Finding the LCM*/
  return newArr[0];
}

smallestCommons([1,5]);
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!