Modo entrevista. Temporizador de 10 min, sin pistas y sin autocompletado
Is the string a palindrome
MediaStrings10 min
Write a function isPalindrome(text) that returns true when the string text is a palindrome and false otherwise.
textis a string of any length. It can be empty.- The compare is exact: every character counts, spaces too, also at the start or the end.
'ab ba'is a palindrome,'top spot'is not. - Letter case matters:
'Abba'is not a palindrome, because'A'and'a'are different characters. - The empty string and a string of one character are palindromes.
- Return a boolean, not a string such as
'yes'.
Ejemplos
isPalindrome('level')Devuelve true
isPalindrome('Abba')Devuelve false
isPalindrome('ab ba')Devuelve true
Preguntada en Infosys · Fuente
Cargando el editor…
- Entrada
isPalindrome('racecar')Esperadotrue - Entrada
isPalindrome('hello')Esperadofalse - Entrada
isPalindrome('')Esperadotrue
Las pruebas ocultas se ejecutan al enviar