Skip to content

Instantly share code, notes, and snippets.

@dabd
Created November 29, 2013 00:56
Show Gist options
  • Save dabd/7700137 to your computer and use it in GitHub Desktop.
Save dabd/7700137 to your computer and use it in GitHub Desktop.
(defn best
[f coll]
(if (seq coll)
(reduce #(if (f %1 %2) %1 %2) coll)
nil))
(defn most
[f coll]
(if (seq coll)
(reduce (fn [[wins wins-score] x]
(let [x-score (f x)]
(if (> wins-score x-score)
[wins wins-score]
[x x-score])))
[(first coll) (f (first coll))] (rest coll))
[nil nil]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment