forked from TheAlgorithms/JavaScript
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem005.js
More file actions
Latest commit
22 lines (18 loc) · 575 Bytes
/
Copy pathProblem005.js
File metadata and controls
22 lines (18 loc) · 575 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
Smallest multiple
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
*/
exportconstfindSmallestMultiple=()=>{
constdivisors=[
20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2
]
letnum=21
letresult
while(!result){
constisDivisibleByAll=divisors.every((divisor)=>num%divisor===0)
if(isDivisibleByAll)result=num
elsenum++
}
returnresult
}