Code Lab

Modo entrevista. Temporizador de 7 min, sin pistas y sin autocompletado

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.

Ejemplos

maxTwoDigit('34987')

Devuelve 98

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

Devuelve 20

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

Devuelve 5

The pair 05 is the number 5.

Preguntada en Druva · Fuente

Cargando el editor…
  1. EntradamaxTwoDigit('34987')
    Esperado98
  2. EntradamaxTwoDigit('1205')
    Esperado20
  3. EntradamaxTwoDigit('05')
    Esperado5

Las pruebas ocultas se ejecutan al enviar