programming-examples/js/Math/Calculate the divisor and modulus of two integers.js
2019-11-15 12:59:38 +01:00

12 lines
317 B
JavaScript

function div_mod(a, b)
{
if (b <= 0)
throw new Error("b cannot be zero. Undefined.");
if (isInt(a) && !isInt(b))
throw new Error("A or B are not integers.");
return [Math.floor(a / b), a % b];
}
function isInt(n) {
return n % 1 === 0;
}
console.log(div_mod(17, 4));