Code Lab

Mode entretien. Minuteur de 10 min, sans indices ni autocomplétion

Is the string a palindrome

MoyenStrings10 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'.

Exemples

isPalindrome('level')

Renvoie true

isPalindrome('Abba')

Renvoie false

isPalindrome('ab ba')

Renvoie true

Posé chez Infosys · Source

Chargement de l'éditeur...
  1. EntréeisPalindrome('racecar')
    Attendutrue
  2. EntréeisPalindrome('hello')
    Attendufalse
  3. EntréeisPalindrome('')
    Attendutrue

Les tests cachés se lancent à la soumission