Palindrome
Mix.install([
{:jason, "~> 1.4"},
{:kino, "~> 0.9", override: true},
{:youtube, github: "brooklinjazz/youtube"},
{:hidden_cell, github: "brooklinjazz/hidden_cell"}
])
Navigation
Home Report An Issue ComprehensionsAnagramPalindrome
A word or sentence that reads the same way forwards and backwards is a palindrome. For example kayak and racecar are palindromes.
You’re going to create a Palindrome
module which can determine if a string is a palindrome.
Palindrome.palindrome?("kayak")
true
Example Solution
defmodule Palindrome do
def palindrome?(string) do
string
|> String.split("")
|> Enum.reverse()
|> Enum.join() == string
end
end
Implement the Palindrome
module as documented below.
defmodule Palindrome do
@moduledoc """
Documentation for `Palindrome`.
"""
@doc """
Determine if a string is a palindrome.
## Examples
iex> Palindrome.palindrome?("baab")
true
iex> Palindrome.palindrome?("racecar")
true
iex> Palindrome.palindrome?("kayak")
true
iex> Palindrome.palindrome?("apples")
false
"""
def palindrome?(string) do
reversed = String.reverse(string)
string === reversed
end
end
Commit Your Progress
DockYard Academy now recommends you use the latest Release rather than forking or cloning our repository.
Run git status
to ensure there are no undesirable changes.
Then run the following in your command line from the curriculum
folder to commit your progress.
$ git add .
$ git commit -m "finish Palindrome exercise"
$ git push
We’re proud to offer our open-source curriculum free of charge for anyone to learn from at their own pace.
We also offer a paid course where you can learn from an instructor alongside a cohort of your peers. We will accept applications for the June-August 2023 cohort soon.