Skip to content

Instantly share code, notes, and snippets.

@Dysperen
Last active September 22, 2016 18:22
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 Dysperen/3be8cf86c821cac9931764d89f58dcd1 to your computer and use it in GitHub Desktop.
Save Dysperen/3be8cf86c821cac9931764d89f58dcd1 to your computer and use it in GitHub Desktop.
module Enumerable
def rolling_mean(n = 3)
raise ArgumentError, "n must be less than array length" if n >= self.size
raise ArgumentError, "n must be a natural number" if n < 0
self.each_cons(n).map { |e| e.mean }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment