Palindrome Challenge

Algorithm Challenge to practice strategies to solve problems in a methodical manner.

Summary / Overview

Our goal is to create a simple app that lets a user type in a word and returns true if it is a palindrome.

A palindrome is a word a word that is spelled the same forwards and backwards Ex:

  • racecar

  • tacocat

  • anna

Using our function:

isPalindrome('racecar');
// True

isPalindrome("tacocat")
//True

isPalindrome("anna")
//True

isPalindrome("Peter")
//False

The above would all return True

Let's dive in to this challenge and try to tackle the palindrome problem.

Setup

Create a new directory called palindrome. Inside the directory create index.html and index.js files.

Implementation

In the index.js file write a function called isPalindrome(). There are several String and Array methods commonly used to solve this problem, but for our purposes we will not be using them

Contraints

  • Cannot use string or array methods

  • isPalendrome must take in a string and return true or false

Step One

Check against the following use cases:

isPalindrome('racecar');
isPalindrome('tacocat');
isPalindrome('anna');

Once you have passed the above test cases, move on to the next step

Step Two

Edge Cases and Refactoring

Inspect your code and look for edge cases where your algorithm does not work. As an engineer you want to think of all the way your program can break and how we can prevent it. Think about how your isPalindrome function can fail Some example edge cases for this problem would be:

  • Does it fail with numbers?

  • Does it work with spaces?

  • If a string has punctuation does that work?

You do not have to code up all the edge cases for this exercise but try to think about what can do wrong.

After thinking about some edge cases is there any way you can refactor your code to have less steps, are you repeating any code (DRY) or can we make it more readable and understandable. We never have a perfect solution to a problem in our code on the first attempt.

Once you are happy with your refactored isPalindrome function and thought about ways your code can break move on to the next step.

Step Three

Adding a User Interface ( UI )

The previous steps must be completed first.

Now that you have working algorithm for detecting if a string is a palindrome lets build a User Interface for it.

User Stories / Requirements

In programming we describe a programs functionality through User Stories. This helps software engineers relate to how the application they are building will be used by the end user. They can also be thought of as application requirements.

Palindrome App User Stories / Requirements

  • As a user I would like to be able to type a word on the page.

  • As a user I would like to be able to submit this word to be checked if it is a palindrome

  • As a user I would like the words I submit to be saved in a palindrome or not palindrome list

  • As a user I would like this list to persist until I refresh the page.

Complete the user stories in order and break down the steps further into smaller steps if needed.

DEMO Palindrome UI

Feel free to add some extra css to make it look nice

Let's dive in to this challenge first and foremost. Partner up with someone and take the next 15 minutes to come up with ideas on how to solve the following algorithm challenge.

During this exercise focus on writing pseudo code and not actual functional code

Last updated