Created
October 19, 2013 17:09
-
-
Save fadelakin/7058608 to your computer and use it in GitHub Desktop.
A function that calculates the average of some numbers in Clojure
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 average | |
[numbers] | |
(/ (apply + numbers) (count numbers))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You might want to use
reduce
instead ofapply
. The former is a lot faster than the latter if you have a lot of numbers.