Last active
November 19, 2015 16:40
-
-
Save caryfitzhugh/ce9e40cf0afe808c2b11 to your computer and use it in GitHub Desktop.
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
(def imgs [{:url "http://media.vanityfair.com/photos/55f700a1fad0d98d444d2531/master/w_690/Pandora_VF_690x460_Girl3_2.jpg"} {:url "http://media.vanityfair.com/photos/55f7002c200c34353591cd5d/master/w_690/Pandora_VF_690x460_Girl3_1.jpg"} | |
{:url "http://media.vanityfair.com/photos/55f7002c200c34353591cd5a/master/w_690/Pandora_VF_690x460_Girl3_2.jpg"}]) | |
(defn remove-dups | |
[images] | |
(:images (reduce (fn [results image] | |
(let [filename (last (clojure.string/split (:url image) #"\/"))] | |
;; If we've already seen this filename. | |
(if (contains? (:filenames results) filename) | |
;; Just return results | |
results | |
;; Otherwise, add the filename to filenames and the image to images | |
{:images (conj (:images results) image) | |
:filenames (conj (:filenames results) filename)}) | |
)) | |
;; Our starting data, is no images and no filenames | |
{:images [] :filenames #{}} | |
images) | |
) | |
) | |
(remove-dups imgs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment