Last active
April 30, 2017 14:25
-
-
Save deque-blog/7b28b0045e80ff4971538fc2d087dc05 to your computer and use it in GitHub Desktop.
This file contains 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 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