Mode entretien. Minuteur de 10 min, sans indices ni autocomplétion
Reverse a string or a number
MoyenStrings10 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
''.
Exemples
reverseValue('hello')Renvoie 'olleh'
reverseValue(1200)Renvoie 21
reverseValue(-45)Renvoie -54
Posé chez Amazon · Source
Chargement de l'éditeur...
- Entrée
reverseValue('hello')Attendu'olleh' - Entrée
reverseValue(12345)Attendu54321 - Entrée
reverseValue(-45)Attendu-54 - Entrée
reverseValue(1200)Attendu21 - Entrée
reverseValue('')Attendu''
Les tests cachés se lancent à la soumission