all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
20
Task/Soundex/Clojure/soundex.clj
Normal file
20
Task/Soundex/Clojure/soundex.clj
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
(defn get-code [c]
|
||||
(case c
|
||||
(\B \F \P \V) 1
|
||||
(\C \G \J \K
|
||||
\Q \S \X \Z) 2
|
||||
(\D \T) 3
|
||||
\L 4
|
||||
(\M \N) 5
|
||||
\R 6
|
||||
nil)) ;(\A \E \I \O \U \H \W \Y)
|
||||
|
||||
(defn soundex [s]
|
||||
(let [[f & s] (.toUpperCase s)]
|
||||
(-> (map get-code s)
|
||||
distinct
|
||||
(concat , "0000")
|
||||
(->> (cons f ,)
|
||||
(remove nil? ,)
|
||||
(take 4 ,)
|
||||
(apply str ,)))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue