Sha256: 93887430c12058a9daf9cc05c4c25f4be39d140e4d4012373ac59d4373a72468

Contents?: true

Size: 870 Bytes

Versions: 322

Compression:

Stored size: 870 Bytes

Contents

module PhoneNumber exposing (..)

import String


nums =
    [ '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' ]


getNumber : String -> Maybe String
getNumber text =
    getValidNum (String.filter isDigit text)


isDigit : Char -> Bool
isDigit char =
    List.any (\n -> n == char) nums


getValidNum : String -> Maybe String
getValidNum num =
    if String.length num == 10 then
        Just num
    else if (String.length num == 11) && (String.left 1 num == "1") then
        Just (String.dropLeft 1 num)
    else
        Nothing


prettyPrint : String -> Maybe String
prettyPrint input =
    Maybe.map formatNumber (getNumber input)


formatNumber : String -> String
formatNumber input =
    String.concat
        [ "("
        , (String.slice 0 3 input)
        , ") "
        , (String.slice 3 6 input)
        , "-"
        , (String.slice 6 10 input)
        ]

Version data entries

322 entries across 322 versions & 1 rubygems

Version Path
trackler-2.2.1.104 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.103 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.102 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.101 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.100 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.99 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.98 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.97 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.96 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.95 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.94 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.93 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.92 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.91 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.90 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.89 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.88 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.87 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.86 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.85 tracks/elm/exercises/phone-number/PhoneNumber.example.elm