In JavaScript, how do I get:
For some number y
and some divisor x
compute the quotient (quotient
)[1] and remainder (remainder
) as:
const quotient = Math.floor(y/x);
const remainder = y % x;
Example:
const quotient = Math.floor(13/3); // => 4 => the times 3 fits into 13
const remainder = 13 % 3; // => 1
[1] The integer number resulting from the division of one number by another