Sha256: b02d3fa2c6577f5b304a2c2d2fa10100bd30458f6bff258bb742fa32388482ae

Contents?: true

Size: 1.49 KB

Versions: 74

Compression:

Stored size: 1.49 KB

Contents

module Isogram exposing (isIsogram)

import Char
import List
import String


isAlpha : Char -> Bool
isAlpha char =
    Char.isUpper char || Char.isLower char


isIsogram : String -> Bool
isIsogram sentence =
    let
        sanitized =
            String.filter isAlpha sentence
                |> String.toLower
                |> String.toList
                |> List.sort
                |> group
    in
    List.all (\x -> List.length x == 1) sanitized



-- Adapted from https://github.com/elm-community/list-extra


group : List a -> List (List a)
group list =
    case list of
        [] ->
            []

        x :: xs ->
            let
                ( ys, zs ) =
                    span ((==) x) xs
            in
            (x :: ys) :: group zs


span : (a -> Bool) -> List a -> ( List a, List a )
span p xs =
    ( takeWhile p xs, dropWhile p xs )


takeWhile : (a -> Bool) -> List a -> List a
takeWhile predicate =
    let
        takeWhileHelper acc list =
            case list of
                [] ->
                    List.reverse acc

                x :: xs ->
                    if predicate x then
                        takeWhileHelper (x :: acc) xs
                    else
                        List.reverse acc
    in
    takeWhileHelper []


dropWhile : (a -> Bool) -> List a -> List a
dropWhile predicate list =
    case list of
        [] ->
            []

        x :: xs ->
            if predicate x then
                dropWhile predicate xs
            else
                list

Version data entries

74 entries across 74 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/elm/exercises/isogram/Isogram.example.elm
trackler-2.2.1.179 tracks/elm/exercises/isogram/Isogram.example.elm
trackler-2.2.1.178 tracks/elm/exercises/isogram/Isogram.example.elm
trackler-2.2.1.177 tracks/elm/exercises/isogram/Isogram.example.elm
trackler-2.2.1.176 tracks/elm/exercises/isogram/Isogram.example.elm
trackler-2.2.1.175 tracks/elm/exercises/isogram/Isogram.example.elm
trackler-2.2.1.174 tracks/elm/exercises/isogram/Isogram.example.elm
trackler-2.2.1.173 tracks/elm/exercises/isogram/Isogram.example.elm
trackler-2.2.1.172 tracks/elm/exercises/isogram/Isogram.example.elm
trackler-2.2.1.171 tracks/elm/exercises/isogram/Isogram.example.elm
trackler-2.2.1.170 tracks/elm/exercises/isogram/Isogram.example.elm
trackler-2.2.1.169 tracks/elm/exercises/isogram/Isogram.example.elm
trackler-2.2.1.167 tracks/elm/exercises/isogram/Isogram.example.elm
trackler-2.2.1.166 tracks/elm/exercises/isogram/Isogram.example.elm
trackler-2.2.1.165 tracks/elm/exercises/isogram/Isogram.example.elm
trackler-2.2.1.164 tracks/elm/exercises/isogram/Isogram.example.elm
trackler-2.2.1.163 tracks/elm/exercises/isogram/Isogram.example.elm
trackler-2.2.1.162 tracks/elm/exercises/isogram/Isogram.example.elm
trackler-2.2.1.161 tracks/elm/exercises/isogram/Isogram.example.elm
trackler-2.2.1.160 tracks/elm/exercises/isogram/Isogram.example.elm