Determine if a word or phrase is an isogram.
An isogram (also known as a "nonpattern word") is a word or phrase without a repeating letter, however spaces and hyphens are allowed to appear multiple times.
Examples of isograms:
The word isograms, however, is not an isogram, because the s repeats.
Execute the tests with:
$ elixir isogram_test.exs
In the test suites, all but the first test have been skipped.
Once you get a test passing, you can unskip the next one by
commenting out the relevant
@tag :pending with a
# @tag :pending test "shouting" do assert Bob.hey("WATCH OUT!") == "Whoa, chill out!" end
Or, you can enable all the tests by commenting out the
ExUnit.configure line in the test suite.
# ExUnit.configure exclude: :pending, trace: true
If you're stuck on something, it may help to look at some of the available resources out there where answers might be found.
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
if !System.get_env("EXERCISM_TEST_EXAMPLES") do Code.load_file("isogram.exs", __DIR__) end ExUnit.start() ExUnit.configure(exclude: :pending, trace: true) defmodule IsogramTest do use ExUnit.Case test "isogram lowercase" do assert Isogram.isogram?("subdermatoglyphic") end @tag :pending test "not isogram lowercase " do refute Isogram.isogram?("eleven") end @tag :pending test "isogram uppercase" do assert Isogram.isogram?("DEMONSTRABLY") end @tag :pending test "not isogram uppercase" do refute Isogram.isogram?("ALPHABET") end @tag :pending test "isogram with dash" do assert Isogram.isogram?("hjelmqvist-gryb-zock-pfund-wax") end @tag :pending test "not isogram with dash" do refute Isogram.isogram?("twenty-five") end @tag :pending test "phrase is isogram" do assert Isogram.isogram?("emily jung schwartzkopf") end @tag :pending test "phrase is not isogram" do refute Isogram.isogram?("the quick brown fox") end end
defmodule Isogram do @doc """ Determines if a word or sentence is an isogram """ @spec isogram?(String.t()) :: boolean def isogram?(sentence) do string_split = sentence |> String.replace(~r/[- ]/, "") |> String.downcase() |> String.split("", trim: true) string_split_unique = Enum.uniq(string_split) Kernel.length(string_split) == Kernel.length(string_split_unique) end end
A huge amount can be learned from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.
Here are some questions to help you reflect on this solution and learn the most from it.