Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Last active April 30, 2017 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deque-blog/7b28b0045e80ff4971538fc2d087dc05 to your computer and use it in GitHub Desktop.
Save deque-blog/7b28b0045e80ff4971538fc2d087dc05 to your computer and use it in GitHub Desktop.
(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