ðŸŽ‰ Exercism Research is now launched. Help Exercism, help science and have some fun at research.exercism.io ðŸŽ‰

# epequeno's solution

## to Isogram in the Elm Track

Published at Apr 22 2021 · 1 comment
Instructions
Test suite
Solution

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.

## Elm Installation

Refer to the Installing Elm page for information about installing elm.

## Writing the Code

The code you have to write is located inside the `src/` directory of the exercise. Elm automatically installs packages dependencies the first time you run the tests so we can start by running the tests from the exercise directory with:

``````\$ elm-test
``````

To automatically run tests again when you save changes:

``````\$ elm-test --watch
``````

As you work your way through the tests suite in the file `tests/Tests.elm`, be sure to remove the `skip <|` calls from each test until you get them all passing!

## Submitting Incomplete Solutions

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

### Tests.elm

``````module Tests exposing (tests)

import Expect
import Isogram exposing (isIsogram)
import Test exposing (..)

tests : Test
tests =
describe "Isogram"
[ test "empty string" <|
\() ->
Expect.equal True <| isIsogram ""
, skip <|
test "isogram with only lower case characters" <|
\() ->
Expect.equal True <| isIsogram "isogram"
, skip <|
test "word with one duplicated character" <|
\() ->
Expect.equal False <| isIsogram "eleven"
, skip <|
test "longest reported english isogram" <|
\() ->
Expect.equal True <| isIsogram "subdermatoglyphic"
, skip <|
test "word with duplicated character in mixed case" <|
\() ->
Expect.equal False <| isIsogram "Alphabet"
, skip <|
test "hypothetical isogrammic word with hyphen" <|
\() ->
Expect.equal True <| isIsogram "thumbscrew-japingly"
, skip <|
test "isogram with duplicated non letter character" <|
\() ->
Expect.equal True <| isIsogram "Hjelmqvist-Gryb-Zock-Pfund-Wax"
, skip <|
test "made-up name that is an isogram" <|
\() ->
Expect.equal True <| isIsogram "Emily Jung Schwartzkopf"
, skip <|
test "duplicated character in the middle" <|
\() ->
Expect.equal False <| isIsogram "accentor"
]``````
``````module Isogram exposing (isIsogram)

isIsogram : String -> Bool
isIsogram sentence =
sentence
|> String.filter Char.isAlpha
|> String.toLower
|> String.toList
|> List.sort
|> anyRepeated
|> not

anyRepeated : List Char -> Bool
anyRepeated xs =
case xs of
[ a, b ] ->
a == b

a :: b :: rest ->
a == b || anyRepeated (b :: rest)

_ ->
False``````