forked from TheAlgorithms/JavaScript
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIsDivisible.js
More file actions
Latest commit
15 lines (13 loc) · 411 Bytes
/
Copy pathIsDivisible.js
File metadata and controls
15 lines (13 loc) · 411 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Checks if a number is divisible by another number.
exportconstisDivisible=(num1,num2)=>{
if(!Number.isFinite(num1)||!Number.isFinite(num2)){
thrownewTypeError('Expected a valid real number')
}
if(num2===0){
returnfalse
}
returnnum1%num2===0
}
// isDivisible(10, 5) // returns true
// isDivisible(123498175, 5) // returns true
// isDivisible(99, 5) // returns false