{{#items}}

{{text}}

{{/items}} {{ctaText}}

{{#items}} {{/items}}

showing results for - "find least common multiple javascript"

Leo

20 Apr 2019

```
1function smallestCommons(arr) {
2 var max = Math.max(...arr);
3 var min = Math.min(...arr);
4 var candidate = max;
5
6 var smallestCommon = function(low, high) {
7 // inner function to use 'high' variable
8 function scm(l, h) {
9 if (h % l === 0) {
10 return h;
11 } else {
12 return scm(l, h + high);
13 }
14 }
15 return scm(low, high);
16 };
17
18 for (var i = min; i <= max; i += 1) {
19 candidate = smallestCommon(i, candidate);
20 }
21
22 return candidate;
23}
24
25smallestCommons([5, 1]); // should return 60
26smallestCommons([1, 13]); // should return 360360
27smallestCommons([23, 18]); //should return 6056820
```

Lloyd

07 Oct 2017

```
1function smallestCommons(arr) {
2 var multiple = [];
3 arr.sort(function(a, b){
4 return a - b;
5
6 });
7 var range = (start, stop, step) => Array.from({ length: (stop - start) / step + 1}, (_, i) => start + (i * step));
8 multiple =range(arr[0], arr[1], 1)
9
10 let max = Math.max(...multiple)
11
12 const small = (current) => n % current === 0;
13 let n = max * (max - 1)
14 let common = false;
15 common = multiple.every(small)
16 while(common === false){
17 n++
18 common = multiple.every(small)
19 }
20
21 return n
22}
23smallestCommons([1,5]); //returns 60
```

similar questions

javascript largest of four numbershow to find hcf of 2 numbers in javascriptlargest number in between a b c javascriptfind length of longest string in array javascriptjavascript find the longest string in arrayget common values from two arrays javascriptjavascript find the second highest element from arrayjavascript return longest string in arrayfind non common elements from 2 arraysjs check for most frequent value in arrayhow to find the smallest two numbers in an array javascriptfind multiple javascriptjsx return greatest number between two numberssecond largest number in array javascriptfind longest palindrome javascript algorithmfind consecutive numbers in an array javascriptjs find lowest number in arrayfind second largest number in array javascriptqueries leading to this page

least common multiple jsjavascript find lcmhow to find hcf and lcm in javascriptsmallest common multiple javascriptlowest common multiple javascripthow to find least common number of string in array javascriptjs find least common multiplehow to find least common multiple in javascriptleast common multiple code javascriptjs least common multiplejavascript lowest common multiplecode for least common multiple of array elements javascriptfind the lowest common denominator of 1 10 javascriptfind smallest common multiple javascriptfind least common multiple javascriptleast common multiple algorithm javascripthow to find the smallest common multiple in a range in javascriptleast common multiple of 2 numbers jsleast common multiple in javascriptfind common mltiples javascriptfind lowest common denominator javascriptjavascript least common multiplefinding lowest common multiple javascripthow to get the lcm maths in javascriptfind least common multiple of array elements javascriptjs find the lowest factor of numbershow to find least common multiple javascriptlcm javascriptfind the smallest common multiple of two numbers in javascripthow to find the greatest common multiple jsfind the smallest common multiple of a number javascriptfind least common multiple of two expressions javascriptlowest common multiple javascript codejavascript find least common multiplejs find lcmleast common multiple javascriptjs calculate minimum common denominatorfind the lowest multiple of a number jsfind the lowest common multiple of a number jsjs find the lowest factor of numberhow to find the least common multiple of a range in javascriptleast common multiple multiple function jsjavascript smallest common multiple functionjs least common multiple n numberssmallest common multiple in javascripthow to find lowest common multiple jsfind common multiples javascriptfind least common multiple javascript your answer for

you will get a confirmation link on this - you will have to click that for successful submission of your answer. we require this to keep the website free of spam, bots and unhelpful content

please ensure to add code which is syntactically corrent and executes properly

ask question on maxinterview

you will get a confirmation link on this - you will have to click that for successful submission of your question. we require this to keep the website free of spam, bots and unhelpful content

please be clear, to the point and respectful