Problem 11
Modulo Recursion Challenge
Given two integers x and y, return the remainder of x divided by y without using the modulo (%), multiplication (*), division (/) operators, or Math methods.
Function Signature
modulo(x, y)
Parameters
x— an integer (dividend). May be positive, negative, or zero.y— an integer (divisor). May be positive, negative, or zero.
Output
Return a number representing the remainder of x / y. If y is 0, return NaN.
Constraints
- The function must use recursion.
- Do not use
*,/,%, orMath. - The function should accept exactly two arguments.
Examples
modulo(5, 2) → 1
modulo(17, 5) → 2
modulo(78, 453) → 78
modulo(0, 32) → 0
modulo(0, 0) → NaN
modulo(-79, 82) → -79
modulo(-4, 2) → 0