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.84 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.83 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.82 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.81 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.80 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.79 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.78 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.77 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.76 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.75 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.74 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.73 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.72 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.71 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.70 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.69 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.68 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.67 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.66 tracks/elm/exercises/phone-number/PhoneNumber.example.elm
trackler-2.2.1.65 tracks/elm/exercises/phone-number/PhoneNumber.example.elm