Sha256: 85e7a8ae6f347446def1d11a63c92e208b28b46fd4520a8560be3935001bb654

Contents?: true

Size: 794 Bytes

Versions: 50

Compression:

Stored size: 794 Bytes

Contents

module PhoneNumber
    ( phoneNumber
    )
    where

import Prelude ((==), (<), (>>=), (&&), ($), otherwise)
import Data.Char.Unicode (isDigit)
import Data.Array (filter, head, tail, length, (!!))
import Data.String (toCharArray, fromCharArray)
import Data.Maybe (Maybe(..), fromMaybe)

clean :: String -> Maybe (Array Char)
clean input = go where
  go
    | len == 10 = Just digits
    | len == 11 && head digits == Just '1' = tail digits
    | otherwise = Nothing
  digits = filter isDigit $ toCharArray input
  len = length digits

check:: Array Char -> Maybe String
check input
  | input !! 0 < Just '2' = Nothing
  | input !! 3 < Just '2' = Nothing
  | otherwise = Just $ fromCharArray input


phoneNumber :: String -> String
phoneNumber input = fromMaybe "None" (clean input >>= check)

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/purescript/exercises/phone-number/examples/src/PhoneNumber.purs
trackler-2.2.1.179 tracks/purescript/exercises/phone-number/examples/src/PhoneNumber.purs
trackler-2.2.1.178 tracks/purescript/exercises/phone-number/examples/src/PhoneNumber.purs
trackler-2.2.1.177 tracks/purescript/exercises/phone-number/examples/src/PhoneNumber.purs
trackler-2.2.1.176 tracks/purescript/exercises/phone-number/examples/src/PhoneNumber.purs
trackler-2.2.1.175 tracks/purescript/exercises/phone-number/examples/src/PhoneNumber.purs
trackler-2.2.1.174 tracks/purescript/exercises/phone-number/examples/src/PhoneNumber.purs
trackler-2.2.1.173 tracks/purescript/exercises/phone-number/examples/src/PhoneNumber.purs
trackler-2.2.1.172 tracks/purescript/exercises/phone-number/examples/src/PhoneNumber.purs
trackler-2.2.1.171 tracks/purescript/exercises/phone-number/examples/src/PhoneNumber.purs
trackler-2.2.1.170 tracks/purescript/exercises/phone-number/examples/src/PhoneNumber.purs
trackler-2.2.1.169 tracks/purescript/exercises/phone-number/examples/src/PhoneNumber.purs
trackler-2.2.1.167 tracks/purescript/exercises/phone-number/examples/src/PhoneNumber.purs
trackler-2.2.1.166 tracks/purescript/exercises/phone-number/examples/src/PhoneNumber.purs
trackler-2.2.1.165 tracks/purescript/exercises/phone-number/examples/src/PhoneNumber.purs
trackler-2.2.1.164 tracks/purescript/exercises/phone-number/examples/src/PhoneNumber.purs
trackler-2.2.1.163 tracks/purescript/exercises/phone-number/examples/src/PhoneNumber.purs
trackler-2.2.1.162 tracks/purescript/exercises/phone-number/examples/src/PhoneNumber.purs
trackler-2.2.1.161 tracks/purescript/exercises/phone-number/examples/src/PhoneNumber.purs
trackler-2.2.1.160 tracks/purescript/exercises/phone-number/examples/src/PhoneNumber.purs