Now it's time to solve a popular coding interview challenge!
WARNING: You will probably feel frustrated at solving these coding challenges - they can become quite difficult!
Given a string, write a method called is_palindrome? to check if it is a palindrome. A palindrome is a word or phrase that is the same read from the front and backwards (for example, "racecar", "eve"). The palindrome does not need to be limited to words in the dictionary (strings like "eyebeye", "bsdfdsb" should be considered palindromes).
Make sure that the method works regardless of capitalization.
EXAMPLE
Your code should run like this:
# Input is_palindrome?("Racecar") # Output true # Input is_palindrome?("rAcEcar") # Output true # Input is_palindrome?("banana") # Output false
Getting Started
First, download the zip from https://github.com/namespace-team/ruby-core-challenges/archive/master.zip
Next, unzip the folder and navigate to the
is_palindromedirectory.cd is_palindromeOnce you are in the folder in the terminal, run the following command:
bundle installNext, run the following command:
rspecThis will run some tests to see if your code is working. Since you haven't written any code yet, you will see that all of the tests fail. The output should look something like this:
Next, open up your text editor and open
palindrome.rblocated insideis_palindrome/lib.You should see code like this:
def is_palindrome?(string) # Write your code here! endImplement your solution in this file.
Once you have implemented the solution, go into your terminal and run this command again:
rspecIf your solution is correct, you should see an output like this:
Good luck!