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.24 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.23 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.22 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.21 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.20 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.19 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.18 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.17 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.16 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.15 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.14 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.13 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.12 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.11 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.10 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.9 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.8 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.7 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.6 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.5 tracks/elm/exercises/phone-number/PhoneNumber.example.elm