Skip to content
Jobless Busters
Runs testsBasic

Palindrome

Write isPalindrome(text). First settle the rules: do we ignore case, spaces and punctuation? In this task we compare all characters and ignore case only.

Following the task's unusual contract, we return true or 0; a normal API would be better off returning a consistent boolean. Compare code points, not UTF-16 units — emoji are characters too.

  • Settle the comparison rules
  • Compare characters from both ends
  • Handle characters outside the BMP (emoji)
  • isPalindrome('Kayak')→ true
  • isPalindrome('React')→ 0
The 4 tests

Tests written from the card: the Kayak/React examples, comparing all characters except case, and an array of code points.

the task's examples

JavaScript
assert.equal(isPalindrome('Kayak'), true);
assert.equal(isPalindrome('React'), 0);

ignores case only

JavaScript
assert.equal(isPalindrome('AbBa'), true);
assert.equal(isPalindrome('kajak '), 0, 'a space is compared like any other character');

empty text and a single character

JavaScript
assert.equal(isPalindrome(''), true);
assert.equal(isPalindrome('x'), true);

compares code points (emoji)

JavaScript
assert.equal(isPalindrome('a😀a'), true);
assert.equal(isPalindrome('😀b'), 0);

Source: Full Stack / JS — task card — The task and reference solution come from the card; the tests were written from its description.

JavaScript · runs in a Web Worker in your browser

Tab indents · Esc, then Tab, leaves the editor · ⌘/Ctrl + Enter runs the tests · Your code is saved in this browser.

Run the tests to check your solution. 4 predefined tests.

Stuck? Hints go from gentle to specific.

Give it a real try first — the solution is most useful after you've struggled a bit.