Created
October 9, 2009 00:00
-
-
Save rduarte/205549 to your computer and use it in GitHub Desktop.
RPCFN: Average Arrival Time For A Flight (#2)
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
require 'time' | |
def average_time_of_day(times) | |
clean = Array.new | |
times.each do |t| | |
parsed = Time.parse(t) | |
parsed += (60*60*24) if parsed < Time.now | |
clean.push(parsed) | |
end | |
clean[ (clean.count / 2.0).ceil - 1 ].strftime("%I:%M%p") | |
end |
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
average_time_of_day(["6:41am", "6:51am", "7:01am"]) | |
=> "06:51AM" | |
average_time_of_day(["11:51pm", "11:56pm", "12:01am", "12:06am", "12:11am"]) | |
=> "12:01AM" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment