Skip to content
Exercise · Strings · lesson 12 of 12

Exercise: palindrome

Write a function function isPalindrome(s) that returns true if s reads the same left to right and right to left, and false otherwise. Capital and small letters count as the same, and spaces are ignored.

  • isPalindrome("level") → true
  • isPalindrome("Never odd or even") → true
  • isPalindrome("hello") → false

Constraints: s has 0 to 100 characters — Latin and Russian letters and spaces; the string may start and end with spaces. The empty string and a string of spaces only are palindromes.

Do not add extra imports unless the task says so explicitly.

palindrome.js — javascript
javascript · 4 lines
Ctrl+Enter run · Esc leave editor

Subscribe to take the course

The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.

Sign in another way