Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(defn sum
[coll]
(loop [total 0
coll coll]
(if (not-empty coll)
(recur (+ total (first coll)) (rest coll))
total)))
(defn average
[coll]
(/ (sum coll) (count coll)))
(sum [1 2 4 5])
=> 12
(average [1 2 4 5])
=> 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment