-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path005-smallest_multiple.js
37 lines (31 loc) · 1.09 KB
/
005-smallest_multiple.js
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
/* Solution Function */
let smallestMult = (largestDivsor) => {
let solution
/* Keeps Track of Potential Solution */
let potentialSolution = largestDivsor
/* Boolean to control while loop */
let unsolved = true
while(unsolved === true){
let currentDivsor
/* Try dividing potential solution by all values from
1 to largest divisor. If any of them produce a remainder,
break out */
for(currentDivsor = 1; currentDivsor <= largestDivsor; currentDivsor ++){
if(potentialSolution % currentDivsor !== 0){
break
}else{
/* If we just successfully divided by the largest
divisor we need, then we have a solution! */
if(currentDivsor === largestDivsor){
solution = potentialSolution
unsolved = false
}
}
}
/* Try next number */
potentialSolution = potentialSolution + 1
}
return solution
}
/* Check Solution */
console.log(smallestMult(20))