Modo entrevista. Temporizador de 5 min, sin pistas y sin autocompletado
Count the digits
FácilBasics5 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'.
Ejemplos
countDigits(12345)Devuelve 5
countDigits(-305)Devuelve 3
countDigits(0)Devuelve 1
Cargando el editor…
- Entrada
countDigits(12345)Esperado5 - Entrada
countDigits(-305)Esperado3 - Entrada
countDigits(0)Esperado1
Las pruebas ocultas se ejecutan al enviar