DEV Community

Discussion on: Daily Challenge #9 - What's Your Number?

Collapse
 
craigmc08 profile image
Craig McIlwrath

Haskell (US formatting):

formatNumber :: [Int] -> Maybe String
formatNumber xs
  | length xs /= 10 = Nothing
  | not $ and $ (map (<10) xs) ++ (map (>=0) xs) = Nothing 
  | otherwise = Just $ "(" ++ (showSlice 0 3 xs) ++ ") " ++ (showSlice 3 3 xs) ++ "-" ++ (showSlice 6 4 xs) 
  where showSlice from len = concat . map show . take len . drop from