Code Lab

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

Is the string a palindrome

MédiaStrings10 min

Write a function isPalindrome(text) that returns true when the string text is a palindrome and false otherwise.

  • text is 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'.

Exemplos

isPalindrome('level')

Retorna true

isPalindrome('Abba')

Retorna false

isPalindrome('ab ba')

Retorna true

Cobrada em Infosys · Fonte

Carregando o editor...
  1. EntradaisPalindrome('racecar')
    Esperadotrue
  2. EntradaisPalindrome('hello')
    Esperadofalse
  3. EntradaisPalindrome('')
    Esperadotrue

Os testes ocultos rodam no envio