Created
July 15, 2011 00:23
-
-
Save jamiltron/1083793 to your computer and use it in GitHub Desktop.
Compress a Sequence
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
;; Compress a sequence: Write a function which removes consecutive duplicates from a sequence. | |
;; old way | |
(defn comp-seq-old [n] | |
(cond | |
(empty? (rest n)) n | |
(= (first n) (first (rest n))) (comp-seq-old (cons (first n) (rest (rest n)))) | |
:else (cons (first n) (comp-seq-old (rest n))))) | |
;; new way | |
(defn comp-seq-new [n] | |
(map first (partition-by identity n))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment