Recursion: Count The Digits

Published by Deep Xavier in

Create a function that will recursively count the number of digits of a number. Conversion of the number to a string is not allowed, thus, the approach is recursive.

Examples

digitsCount(4666) ➞ 4

digitsCount(544) ➞ 3

digitsCount(121317) ➞ 6

digitsCount(0) ➞ 1

digitsCount(12345) ➞ 5

digitsCount(1289396387328L) ➞ 13

Notes

  • All inputs are integers but some are in exponential form, deal with it accordingly.
  • You are expected to come up with a solution using the concept of recursion or the so-called recursive approach.
  • Check out the Resources for more topics about recursion to read on (if you aren't familiar with it yet or haven't fully understood the concept behind it before taking up this challenge or unless otherwise).
  • An iterative version of this challenge can be found via this link.
  • A collection of challenges alike can be found via this link.
Watch a quick demo on how Edabit works.

ProTip

Ctrl + Enter to check code.