DEV Community

Discussion on: Daily Challenge #254 - The Vowel Code

Collapse
 
quoll profile image
Paula Gearon

A symmetric solution is probably better, but indexing letters but a number just called out to me for an array, even if the characters need to be converted to numbers to do so...

(def e {\a 1 \e 2 \i 3 \o 4 \u 5})
(def d [\a\e\i\o\u])

(defn encode [s] (apply str (map #(get e % %) s)))
(defn decode [s] (apply str (map #(get d (- (int %) (int \1)) %) s)))