Created
May 13, 2014 20:37
-
-
Save k0nserv/b6138b30d9a7d2b938f6 to your computer and use it in GitHub Desktop.
Opening hours
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
def hours(open, close) | |
(0..6).to_a.map do |x| | |
{ | |
start: x * 24 + open, | |
end: x * 24 + close | |
} | |
end | |
end | |
# Could be binary search | |
def is_open?(hour, open_hours) | |
open_hours.each do |hours| | |
return true if hour >= hours[:start] and hour <= hours[:end] | |
end | |
return false | |
end | |
my_hours = hours 8, 18 | |
is_open?(9, my_hours) # Open monday morning at 9? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment