Modo entrevista. Temporizador de 10 min, sin pistas y sin autocompletado
Reverse a string or a number
MediaStrings10 min
Write a function reverseValue(value) that reverses a string or a whole number.
valueis a string or an integer from-1000000000to1000000000.- For a string, return the string with its characters in reverse order:
'hello'gives'olleh'. - For a number, return a number with its digits in reverse order. The minus sign stays in front:
-45gives-54. Zeros at the start of the result drop:1200gives21, and0gives0. - The result has the same type as
value: a number gives a number, not a string. A string of digits is still a string:'120'gives'021'. - The empty string gives
''.
Ejemplos
reverseValue('hello')Devuelve 'olleh'
reverseValue(1200)Devuelve 21
reverseValue(-45)Devuelve -54
Preguntada en Amazon · Fuente
Cargando el editor…
- Entrada
reverseValue('hello')Esperado'olleh' - Entrada
reverseValue(12345)Esperado54321 - Entrada
reverseValue(-45)Esperado-54 - Entrada
reverseValue(1200)Esperado21 - Entrada
reverseValue('')Esperado''
Las pruebas ocultas se ejecutan al enviar