Count the digits
EasyBasics5 min
Write a function countDigits(n) that returns how many digits the integer n has.
nis an integer from-999999999999999to999999999999999, so it has at most 15 digits. It can be negative or zero.- The minus sign is not a digit:
countDigits(-305)is3. 0is written with one digit, socountDigits(0)is1.- Return a number, for example
5, not the string'5'.
Examples
countDigits(12345)Returns 5
countDigits(-305)Returns 3
countDigits(0)Returns 1
Loading the editor...
- Input
countDigits(12345)Expected5 - Input
countDigits(-305)Expected3 - Input
countDigits(0)Expected1
Hidden tests run on Submit