Created
February 4, 2014 21:26
-
-
Save skatenerd/8812666 to your computer and use it in GitHub Desktop.
compare
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
(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