Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
require 'time'
def average_time_of_day(array_of_times)
total = array_of_times.inject(0) { |total,current| total + Time.parse(current).to_i }
Time.at(total / array_of_times.size).strftime('%I:%M %p').downcase!
end
# Assumes same day
puts average_time_of_day(["12:00 am", "11:59 pm", "11:53 pm"])
# Also works
puts average_time_of_day(["Nov 2 12:00 am", "Nov 1 11:59 pm", "Nov 1 11:53 pm"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.