Skip to content

Instantly share code, notes, and snippets.

@amalloy
Created April 4, 2011 19:32
Show Gist options
  • Select an option

  • Save amalloy/902251 to your computer and use it in GitHub Desktop.

Select an option

Save amalloy/902251 to your computer and use it in GitHub Desktop.
Gisted version of jsa's comment on What is Clojure
(defn largest-size [kfn l item]
(if (empty? l)
item
(if (nil? item)
(recur kfn (next l) (first l))
(let [f (first l)]
(recur kfn
(next l)
(if (> (kfn f) (kfn item)) f item))))))
(largest-size identity '(1 3 8 5 77 33 3 99 22) nil)
=> 99
(largest-size identity [1 3 8 5 77 33 3 99 22] nil)
=> 99
(largest-size val {:one 1 :two 3 :three 8 :four 5 :five 77 :six 33 :seven 3 :eight 99 :nine 22} nil)
=> [:eight 99]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment