Skip to content

Instantly share code, notes, and snippets.

@reinh
Created September 25, 2009 21:46
Show Gist options
  • Save reinh/193873 to your computer and use it in GitHub Desktop.
Save reinh/193873 to your computer and use it in GitHub Desktop.
# Compute an average for <back> elements from the end of the results
def average_value(back, results)
return results['values'].last['value'] if back.zero?
values = results['values'].map { |item| item['value'] }
values[-back, back].inject {|sum, i| sum + i} / range_of_interest.size.to_f
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment