Skip to content

Commit f6329c6

Browse files
committed
added smallest common multiple to math folder
1 parent 2789ecf commit f6329c6

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

math/smallest-common-multiple.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Find the smallest common multiple of the given parameters that can be evenly divided by both, as well as
2+
// by all numbers in the range between these parameters.
3+
// The range is an array of two numbers, not necessarily be in numerical order.
4+
5+
function smallestCommons(arr) {
6+
arr.sort(function(a, b) { //sorting given numbers
7+
return b - a;
8+
});
9+
10+
var num = [];
11+
for (var i = arr[0]; i >= arr[1]; i--) { //create array of all nums
12+
num.push(i);
13+
}
14+
15+
var quot = 0; //variables for the quotient that can access them outside the loop
16+
var loop = 1;
17+
var n;
18+
// Run code while n is not the same as the array length.
19+
do {
20+
quot = num[0] * loop * num[1];
21+
for (n = 2; n < num.length; n++) {
22+
if (quot % num[n] !== 0) {
23+
break;
24+
}
25+
}
26+
loop++;
27+
} while (n !== num.length);
28+
29+
return quot;
30+
}
31+
32+
smallestCommons([1,5]);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy