Skip to content

Instantly share code, notes, and snippets.

@matthewd
Forked from baweaver/musicalEra.js
Last active October 9, 2017 02:09
Show Gist options
  • Save matthewd/558b2cbf98e569f170ba272654a5d250 to your computer and use it in GitHub Desktop.
Save matthewd/558b2cbf98e569f170ba272654a5d250 to your computer and use it in GitHub Desktop.
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