Exercism v3 launches on Sept 1st 2021. Learn more! ๐Ÿš€๐Ÿš€๐Ÿš€
Avatar of thekeele

thekeele's solution

to Isogram in the Elixir Track

Published at Nov 05 2019 · 0 comments
Test suite

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:

  • lumberjacks
  • background
  • downstream
  • six-year-old

The word isograms, however, is not an isogram, because the s repeats.

Running tests

Execute the tests with:

$ mix test

Pending tests

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 # symbol.

For example:

# @tag :pending
test "shouting" do
  assert Bob.hey("WATCH OUT!") == "Whoa, chill out!"

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.


Wikipedia https://en.wikipedia.org/wiki/Isogram

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.


defmodule IsogramTest do
  use ExUnit.Case

  test "isogram lowercase" do
    assert Isogram.isogram?("subdermatoglyphic")

  @tag :pending
  test "not isogram lowercase " do
    refute Isogram.isogram?("eleven")

  @tag :pending
  test "isogram uppercase" do
    assert Isogram.isogram?("DEMONSTRABLY")

  @tag :pending
  test "not isogram uppercase" do
    refute Isogram.isogram?("ALPHABET")

  @tag :pending
  test "isogram with dash" do
    assert Isogram.isogram?("hjelmqvist-gryb-zock-pfund-wax")

  @tag :pending
  test "not isogram with dash" do
    refute Isogram.isogram?("twenty-five")

  @tag :pending
  test "phrase is isogram" do
    assert Isogram.isogram?("emily jung schwartzkopf")

  @tag :pending
  test "phrase is not isogram" do
    refute Isogram.isogram?("the quick brown fox")


ExUnit.configure(exclude: :pending, trace: true)
defmodule Isogram do
  @spec isogram?(String.t()) :: boolean
  def isogram?(sentence) do
    letters = sentence |> String.replace(["-", " "], "") |> String.codepoints()

    letters === Enum.uniq(letters)

Community comments

Find this solution interesting? Ask the author a question to learn more.

What can you learn from this solution?

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.

  • What compromises have been made?
  • Are there new concepts here that you could read more about to improve your understanding?