2020-10-09 14:41:58 -03:00
|
|
|
// Checks if a number is divisible by another number.
|
|
|
|
|
|
2021-05-05 14:22:10 +09:00
|
|
|
export const isDivisible = (num1, num2) => {
|
|
|
|
|
if (!Number.isFinite(num1) || !Number.isFinite(num2)) {
|
2022-06-21 13:17:45 -04:00
|
|
|
throw new TypeError('Expected a valid real number')
|
2020-10-09 14:41:58 -03:00
|
|
|
}
|
|
|
|
|
if (num2 === 0) {
|
2021-05-05 14:22:10 +09:00
|
|
|
return false
|
2020-10-09 14:41:58 -03:00
|
|
|
}
|
|
|
|
|
return num1 % num2 === 0
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-10 17:55:08 +02:00
|
|
|
// isDivisible(10, 5) // returns true
|
|
|
|
|
// isDivisible(123498175, 5) // returns true
|
|
|
|
|
// isDivisible(99, 5) // returns false
|