Code Lab

Is the string a palindrome

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

Examples

isPalindrome('level')

Returns true

isPalindrome('Abba')

Returns false

isPalindrome('ab ba')

Returns true

Asked at Infosys · Source

Loading the editor...
  1. InputisPalindrome('racecar')
    Expectedtrue
  2. InputisPalindrome('hello')
    Expectedfalse
  3. InputisPalindrome('')
    Expectedtrue

Hidden tests run on Submit.