Avatar of ahasan

ahasan's solution

to Isogram in the Elm Track

Published at Aug 27 2019 · 0 comments
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 first time you start an exercise, you'll need to ensure you have the appropriate dependencies installed. Thankfully, Elm makes that easy for you and will install dependencies when you try to run tests or build the code.

Execute the tests with:

$ elm-test

Automatically run tests again when you save changes:

$ elm-test --watch

As you work your way through the test suite, be sure to remove the skip <| calls from each test until you get them all passing!

Source

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

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)

import Char
import List
import Set
import String


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


listEqual : List Char -> Bool
listEqual charList =
    List.length charList == Set.size (Set.fromList charList)

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?