Code Lab

Modo entrevista. Cronômetro de 7 min, sem dicas e sem autocompletar

Largest two-digit number

FácilStrings7 min

The input is a string of digits, at least two characters long. Write a function maxTwoDigit(digits) that finds the largest number made of two neighbouring digits and returns it as a number.

Exemplos

maxTwoDigit('34987')

Retorna 98

The pairs are 34, 49, 98 and 87.
maxTwoDigit('1205')

Retorna 20

Only neighbouring digits are taken.
maxTwoDigit('05')

Retorna 5

The pair 05 is the number 5.

Cobrada em Druva · Fonte

Carregando o editor...
  1. EntradamaxTwoDigit('34987')
    Esperado98
  2. EntradamaxTwoDigit('1205')
    Esperado20
  3. EntradamaxTwoDigit('05')
    Esperado5

Os testes ocultos rodam no envio