find least common multiple javascript

function smallestCommons(arr) {
  var max = Math.max(...arr);
  var min = Math.min(...arr);
  var candidate = max;

  var smallestCommon = function(low, high) {
    // inner function to use 'high' variable
    function scm(l, h) {
      if (h % l === 0) {
        return h;
      } else {
        return scm(l, h + high);
      }
    }
    return scm(low, high);
  };

  for (var i = min; i <= max; i += 1) {
    candidate = smallestCommon(i, candidate);
  }

  return candidate;
}

smallestCommons([5, 1]); // should return 60
smallestCommons([1, 13]); // should return 360360
smallestCommons([23, 18]); //should return 6056820

4
8
Awgiedawgie 440215 points

                                    function smallestCommons(arr) {
  var multiple = [];
   arr.sort(function(a, b){
    return a - b;
    
  });
  var range = (start, stop, step) =&gt; Array.from({ length: (stop - start) / step + 1}, (_, i) =&gt; start + (i * step));
  multiple =range(arr[0], arr[1], 1)
  
  let max = Math.max(...multiple)
  
  const small = (current) =&gt; n % current === 0;
  let n = max * (max - 1)
  let common = false;
  common = multiple.every(small)
  while(common === false){
    n++
    common = multiple.every(small)
  }
  
  return n
}
smallestCommons([1,5]); //returns 60

4 (8 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
least common multiple algorithm javascript how to find lowest common multiple js javascript lowest common multiple code for Least Common Multiple of array elements javascript find Least Common Multiple of array elements javascript js find least common multiple how to find least common multiple in javascript find least common multiple of two expressions javascript js least common multiple n numbers js least common multiple how to find the greatest common multiple js lowest common multiple javascript least common multiple multiple function js lowest common multiple javascript code lcm javascript find the smallest common multiple of two numbers in javascript find the smallest common multiple of a number javascript find lowest common denominator javascript javascript least common multiple javascript find least common multiple how to find hcf and lcm in javascript find the lowest multiple of a number js find the lowest common multiple of a number js js find lcm javascript Smallest Common Multiple function how to get the lcm maths in javascript find the lowest common denominator of 1 - 10 javascript find common multiples javascript find common mltiples javascript find smallest common multiple javascript Smallest Common Multiple in javascript how to find the least common multiple of a range in javascript how to find the smallest common multiple in a range in javascript least common multiple javascript least common multiple code javascript js find the lowest factor of number js find the lowest factor of numbers smallest common multiple javascript javascript find lcm how to find least common multiple javascript js calculate minimum common denominator find least common multiple javascript
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source