Modo entrevista. Temporizador de 10 min, sin pistas y sin autocompletado
Print if a text is a palindrome
MediaStrings10 min
Write a function checkPalindrome(text) that checks if the string text is a palindrome, prints the answer with console.log and returns it as a boolean.
- Only Latin letters (
atoz,AtoZ) and digits (0to9) count. Skip every other character: spaces, commas, question marks, underscores and so on. - The check is case insensitive:
'A man, a plan, a canal: Panama'is a palindrome. - Digits count like letters:
'0P'is not a palindrome. - A string with no letters and no digits, the empty string too, is a palindrome.
- Print exactly one line:
"<text>" is a palindromeor"<text>" is not a palindrome. Here<text>is the originaltext, unchanged, inside double quotes. - Return
trueorfalse.
A regular expression can remove the characters that do not count.
Ejemplos
checkPalindrome('A man, a plan, a canal: Panama')Devuelve true
Imprime "A man, a plan, a canal: Panama" is a palindrome
checkPalindrome('hello')Devuelve false
Imprime "hello" is not a palindrome
Preguntada en ServiceNow · Fuente
Cargando el editor…
- Entrada
checkPalindrome('A man, a plan, a canal: Panama')EsperadotrueSalida"A man, a plan, a canal: Panama" is a palindrome - Entrada
checkPalindrome('hello')EsperadofalseSalida"hello" is not a palindrome
Las pruebas ocultas se ejecutan al enviar