Code Lab

Mode entretien. Minuteur de 7 min, sans indices ni autocomplétion

Largest two-digit number

FacileStrings7 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.

Exemples

maxTwoDigit('34987')

Renvoie 98

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

Renvoie 20

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

Renvoie 5

The pair 05 is the number 5.

Posé chez Druva · Source

Chargement de l'éditeur...
  1. EntréemaxTwoDigit('34987')
    Attendu98
  2. EntréemaxTwoDigit('1205')
    Attendu20
  3. EntréemaxTwoDigit('05')
    Attendu5

Les tests cachés se lancent à la soumission