Last active
May 7, 2016 05:13
-
-
Save caged/c42ddd2ab41e80bdaa7a1b67f55ac0d4 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
require 'csv' | |
coach_years=CSV.read('coaches2.csv')[1..-1] | |
stints = coach_years.sort_by(&:reverse).each_with_object([]) do |coach_year, coach_stints| | |
season, coach = coach_year | |
start_year = season.split('-')[0].to_i | |
end_year = start_year + 1 | |
last_stint = coach_stints.last | |
if [coach, start_year] == last_stint&.fetch_values(:coach, :end_year) | |
last_stint[:end_year] = end_year | |
else | |
coach_stints << { coach: coach, start_year: start_year, end_year: end_year } | |
end | |
end | |
stints.sort_by!{|s| [s[:start_year], s[:end_year]]} | |
puts stints |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment