-
-
Save matthewd/558b2cbf98e569f170ba272654a5d250 to your computer and use it in GitHub Desktop.
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
class Range | |
def overlap(other) | |
[self.begin, other.begin].max .. [self.end, other.end].min | |
end | |
end | |
def musical_era_alive_in(start_life, end_life) | |
[ | |
['Medieval', 476..1400], | |
['Renaissance', 1400..1600], | |
['Baroque', 1600..1760], | |
['Classical', 1730..1820], | |
['Romantic', 1815..1910], | |
['Modern', 1900..2100] | |
].max_by { |_, r| r.overlap(start_life..end_life).size }.first | |
end | |
puts musical_era_alive_in(1800, 1950) # Romantic |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment