Recursion: Multiplication by Addition

Published by Deep Xavier in

Create a function that returns the product of two integers. This process of multiplication can be achieved via repetitive addition, thus, the process can be done recursively.

Examples

multiply(10, 2) ➞ 20

multiply(-51, -4) ➞ 204

multiply(3, 9) ➞ 27

multiply(-21, 5) ➞ -105

multiply(1024, 7) ➞ 7168

multiply(273, -6) ➞ -1638

Notes

  • 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.
Watch a quick demo on how Edabit works.