Skip to content

Instantly share code, notes, and snippets.

@caryfitzhugh
Last active November 19, 2015 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caryfitzhugh/ce9e40cf0afe808c2b11 to your computer and use it in GitHub Desktop.
Save caryfitzhugh/ce9e40cf0afe808c2b11 to your computer and use it in GitHub Desktop.
(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