Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions Maths/IsDivisible.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
// Checks if a number is divisible by another number.

export const isDivisible = (num1, num2) => {
function checkFiniteNumbers(num1, num2) {
if (!Number.isFinite(num1) || !Number.isFinite(num2)) {
throw new TypeError('Expected a valid real number')
throw new TypeError('Expected valid real numbers');
}

return true;
}

function isZero(num2){
if (num2 === 0) {
return false
}
return num1 % num2 === 0
}

// isDivisible(10, 5) // returns true
// isDivisible(123498175, 5) // returns true
// isDivisible(99, 5) // returns false
export const isDivisible = (num1, num2) => {
checkFiniteNumbers(num1, num2);
if(isZero(num2))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(isZero(num2))
if(num2 !== 0)
return num1 % num2 === 0
}