Code Lab

Modo entrevista. Cronômetro de 10 min, sem dicas e sem autocompletar

Print if a text is a palindrome

MédiaStrings10 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 (a to z, A to Z) and digits (0 to 9) 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 palindrome or "<text>" is not a palindrome. Here <text> is the original text, unchanged, inside double quotes.
  • Return true or false.

A regular expression can remove the characters that do not count.

Exemplos

checkPalindrome('A man, a plan, a canal: Panama')

Retorna true

Imprime "A man, a plan, a canal: Panama" is a palindrome

checkPalindrome('hello')

Retorna false

Imprime "hello" is not a palindrome

Cobrada em ServiceNow · Fonte

Carregando o editor...
  1. EntradacheckPalindrome('A man, a plan, a canal: Panama')
    Esperadotrue
    Saída"A man, a plan, a canal: Panama" is a palindrome
  2. EntradacheckPalindrome('hello')
    Esperadofalse
    Saída"hello" is not a palindrome

Os testes ocultos rodam no envio