Created
November 28, 2015 15:30
-
-
Save sanatgersappa/3d472675bbd06ffa84a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn get-digit [n] | |
(cond | |
(nil? n) "_" | |
(nil? (re-find #"\d" (str n))) "" | |
:else n)) | |
(defn get-char [n] | |
(cond | |
(nil? n) "_" | |
(nil? (re-find #"[A-Za-z]" (str n))) "" | |
:else n)) | |
(defn apply-mask [mask input] | |
(loop [filteredmask mask i input output ""] | |
(let [m (first filteredmask)] | |
(cond | |
(nil? m) (if (= "" output) i output) | |
(= "#" (str m)) (recur (rest filteredmask) (rest i) (str output (get-digit (first i)))) | |
(= "x" (str m)) (recur (rest filteredmask) (rest i) (str output (get-char (first i)))) | |
:else (recur (rest filteredmask) i (str output m)))))) | |
(apply-mask "(###) ### ####" "6666666666") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment