Skip to content

Latest commit

 

History

History
32 lines (24 loc) · 1.46 KB

exercise-string-palindrome.md

File metadata and controls

32 lines (24 loc) · 1.46 KB

Exercise: Fun with Palindromes

These exercises will give you more experience using strings and the clojure.string library.

Note::Simple Palindrome Checker

A Palindrome is a word that is spelt the same whether it is written backwards or forwards. So when you reverse the word it should still look the same.

Can you write a simple expression to see if a word, e.g. "radar", is a palindrome.

You will need to reverse the word and compare (see if it is equal) to the original word.

()

Hint::Clojure.string library

The clojure.string library has some handy functions for manipulating strings.

Using functions on strings that are not part of the clojure.string library can give 'interesting' results.

Using a function called reverse in the clojure.string library

;; Is the reverse of the string "radar" equal to the string "radar"
(= "radar" (clojure.string/reverse "radar"))

You could use the generic reverse function in clojure.core, however this returns a list the individual characters in reverse order, rather than reversing the string as a single value.