Created
January 31, 2015 00:33
-
-
Save eldritchideen/b8edcea93ced80b03f53 to your computer and use it in GitHub Desktop.
Moving Average in Clojure
This file contains hidden or 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 [coll] | |
(/ (reduce + coll) | |
(count coll))) | |
(defn ma [period coll] | |
(lazy-cat (repeat (dec period) nil) | |
(map average (partition period 1 coll)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Another interesting implementation from StackOverflow