Problem 13

Divide Recursion Challenge

Given two integers, return the whole-number quotient of x divided by y without using the multiplication (*), division (/), or modulo (%) operators, or Math methods. Ignore any decimal remainder.

Function Signature

divide(x, y)

Parameters

  • x — an integer (dividend).
  • y — an integer (divisor).

Output

Return a number representing the integer quotient of x / y (truncated toward zero). If y is 0, return NaN.

Constraints

  • The function must use recursion.
  • Do not use *, /, %, or Math.
  • The function should accept exactly two arguments.

Examples

divide(17, 5)      → 3
divide(2, 1)       → 2
divide(78, 453)    → 0
divide(0, 32)      → 0
divide(0, 0)       → NaN
divide(-79, 82)    → 0
divide(-275, -582) → 0