re: Daily Challenge #32 - Hide Phone Numbers VIEW POST

FULL DISCUSSION
 

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)
 
 

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

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.

code of conduct - report abuse