Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- In Clojure.
- [sourcecode lang="css"]
- ;; helpers
- (defn build-string-step [search-criteria]
- (fn [built-so-far next-character]
- (if (search-criteria built-so-far next-character)
- built-so-far
- (conj built-so-far next-character))))
- (defn make-string-transformer [f]
- (fn [string]
- (apply str
- (reduce (build-string-step f) [] string))))
- ;; solve exercise 1
- (def rem-dups
- (make-string-transformer
- (fn [built-so-far next-character]
- (some #(= % next-character) built-so-far))))
- ;; solve exercise 2
- (def squash-spaces
- (make-string-transformer
- (fn [built-so-far next-character]
- (and (= next-character \space) (= (last built-so-far) \space)))))
- [/sourcecode]
Add Comment
Please, Sign In to add comment