← Back to challenges

Count the Digits

JavaScriptHardnumberslogic

Instructions

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

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.
  • A recursive version of this challenge can be found via this link.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.