Modo entrevista. Cronômetro de 5 min, sem dicas e sem autocompletar
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'.
Exemplos
countDigits(12345)Retorna 5
countDigits(-305)Retorna 3
countDigits(0)Retorna 1
Carregando o editor...
- Entrada
countDigits(12345)Esperado5 - Entrada
countDigits(-305)Esperado3 - Entrada
countDigits(0)Esperado1
Os testes ocultos rodam no envio