-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmallestCommonDenominator.js
More file actions
58 lines (36 loc) · 1.6 KB
/
SmallestCommonDenominator.js
File metadata and controls
58 lines (36 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function smallestCommons(arr) {
var topOfRange;
var bottomOfRange;
var currentLowestMultiple;
var isMultipleOfAllValues = false;
if (arr[0] > arr[1]) {
topOfRange = arr[0];
bottomOfRange = arr[1];
} else {
topOfRange = arr[1];
bottomOfRange = arr[0];
}
currentLowestMultiple = topOfRange * bottomOfRange;
var counter = topOfRange - 1;
while (!isMultipleOfAllValues) {
if (currentLowestMultiple % counter !== 0) {
currentLowestMultiple *= counter;
}
else if (counter === (bottomOfRange + 1)) {
isMultipleOfAllValues = true;
}
counter--;
console.log("multipleLowest: " +currentLowestMultiple);
console.log("counter: " + counter);
}
return currentLowestMultiple;
}
console.log(smallestCommons([1, 10]));
/*
1 - generate next multiple function(currentMultiple, bottomOfRange, topOfRange)
a - start by multiplying topOfRange * bottomOfRange;
b - test for even divided % for loop through range topOfRange to bottomOfRange
i - if one value does not pass this test multiply the current multiple value, continue down the loop
/*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.
e.g. for 1 and 3 - find the smallest common multiple of both 1 and 3 that is evenly divisible by all numbers between 1 and 3.*/