Recursion: Integer Division

Published by Deep Xavier in

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.
  • You can read on more topics about recursion (see Resources tab) if you aren't familiar with it yet or haven't fully understood the concept behind it before taking up this challenge.
  • If you think recursion is fun, you can find a collection of those challenges here.
Watch a quick demo on how Edabit works.