Skip to content

Instantly share code, notes, and snippets.

@skatenerd
Created February 4, 2014 21:26
Show Gist options
  • Save skatenerd/8812666 to your computer and use it in GitHub Desktop.
Save skatenerd/8812666 to your computer and use it in GitHub Desktop.
compare
(defn compare-tuples [tuple-1 tuple-2]
(or (first (remove zero? (map compare tuple-1 tuple-2))) 0))
(defn get-values-at [record keys]
(map #(get record %) keys))
(defn sort-by-keys [keys to-sort]
(sort-by #(get-values-at % keys) compare-tuples to-sort))
(def people [
{:age 0, :salary 999999, :height 23}
{:age 29, :salary 1000, :height 100}
{:age 29, :salary 1000009, :height 2}
{:age 29, :salary 1000009, :height 191919191919}
{:age 0, :salary 999999, :height 23}])
(sort-by-keys [:age :salary :height] people)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment