DEV Community

loading...

Discussion on: Daily Challenge #32 - Hide Phone Numbers

Collapse
avalander profile image
Avalander

Today I'm folding the other way around. I've chosen not to validate the number format because I didn't want to spend the entire evening building a regex that matched all possible formats I can think of.

import Data.Char (isDigit)

hide_nums :: String -> String
hide_nums = snd . foldr kevin (0, "")
    where
        kevin :: Char -> (Int, String) -> (Int, String)
        kevin char (x, result)
            | x >= 6       = (x, char:result)
            | isDigit char = (x + 1, 'x':result)
            | otherwise    = (x, char:result)
Collapse
mandaputtra profile image
Manda Putra

There no package for phone numbers?

Collapse
avalander profile image
Avalander

Using a library kinda defeats the purpose of these exercises, don't you think?

Thread Thread
ajinspiro profile image
Arun Kumar

But what's the fun in that?

Thread Thread
mandaputtra profile image
Manda Putra

Yes I'm just asking 😄 of there are one I'll use it, working with phone number is a bit hardwork since others country had different types phone code.