Skip to the content

Is it a palindrome?

Problem

A palindrome reads the same forwards and backwards, like "racecar".

Write a function that takes a text and returns true if it is a palindrome and false if it isn't.

The rules: spaces don't count, so "Never odd or even" is a palindrome. Capitals don't count either: "A" and "a" are the same letter. Every other character does count, and the texts in the tests come with no punctuation marks.

An empty text reads the same both ways, so with it you return true.

Examples

  • "racecar" → true

  • "hello" → false

  • With spaces and capitals

    "Never odd or even" → true

  • With spaces but it isn't

    "happy dog" → false

Besides these, the challenge has hidden tests that are revealed when you submit your solution.

You start with this

Python

def is_palindrome(text):
    pass

JavaScript

function isPalindrome(text) {
}
Solve this challenge

It opens in your browser, with the editor and the tests. This challenge is part of the full plan; the O(1) and O(log n) ones are free.

More O(n) challenges

See all challenges →