-
-
Save Dysperen/3be8cf86c821cac9931764d89f58dcd1 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
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