Created
August 18, 2017 19:01
-
-
Save dandorman/d0516cd4f73b76231408e3132627f4cf to your computer and use it in GitHub Desktop.
A little Clojure(Script) solution for a weird little problem.
This file contains hidden or 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
#!/usr/bin/env planck | |
(def vowel? #{\A \a \E \e \I \i \O \o \U \u}) | |
(defn reverse-vowels | |
"Takes in a string and reverses all the vowels in the string." | |
[in] | |
(let [idx->letter (zipmap (range) in) | |
idx->vowel (filter (fn [[_ letter]] (vowel? letter)) idx->letter) | |
[idxes vowels] ((juxt keys vals) idx->vowel) | |
ridx->vowel (zipmap (reverse idxes) vowels)] | |
(apply | |
str | |
(reduce (fn [out [idx letter]] (assoc out idx letter)) | |
(into [] (range (count in))) | |
(merge idx->letter ridx->vowel))))) | |
(println (reverse-vowels "I love burritos")) | |
;; => o livu berrotIs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment