Modo entrevista. Temporizador de 10 min, sin pistas y sin autocompletado
Middle three characters
MediaStrings10 min
Write a function middleThree(text) that returns the three characters in the middle of the string text: 'NewMumbai' gives 'Mum'.
textis plain Latin text from 0 to 1000 characters. Every character counts, spaces and signs too, also at the start and the end. Do not trim the text.- If the length of
textis 3 or less, returntextas it is. For an empty string return''. - If the length is odd and more than 3, return the middle three characters: the same number of characters stays on the left and on the right of them.
- If the length is even and more than 3, there is no single middle. Return null, not
''.
You can cut the part out with slice.
Ejemplos
middleThree('NewMumbai')Devuelve 'Mum'
middleThree('abcd')Devuelve null
middleThree('ab')Devuelve 'ab'
Preguntada en EPAM · Fuente
Cargando el editor…
- Entrada
middleThree('NewMumbai')Esperado'Mum' - Entrada
middleThree('abcd')Esperadonull - Entrada
middleThree('ab')Esperado'ab'
Las pruebas ocultas se ejecutan al enviar