← Back to challenges

Recursion: Integer Division

JavaScriptHardrecursionnumbers

Instructions

Create a function that returns the integral part from the result of a division between two numbers. This process of division can be achieved via repetitive subtraction, thus, it can be done recursively.

Examples

divide(10, 2) ➞ 5

divide(-51, -4) ➞ 12

divide(3, 9) ➞ 0

divide(-21, 5) ➞ -4

divide(1024, 7) ➞ 146

divide(273, -6) ➞ -45

Notes

  • There will be no zero-values for the divisor.
  • You're expected to solve this challenge using a recursive approach.
  • If you think recursion is fun, you can find a collection of those challenges here.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.