Last active
September 8, 2017 03:10
-
-
Save matthewpick/2a6975cdb199288c5dd820635ceeac02 to your computer and use it in GitHub Desktop.
Based on a bi-weekly pay cycle, determine which months you will receive an extra paycheck.
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
require 'active_support/time' | |
def paycheck_count(begin_date, years) | |
month_count = {} | |
end_date = begin_date + years.years | |
time_counter = begin_date | |
while time_counter < end_date do | |
key = "#{time_counter.year}.#{time_counter.month}" | |
if month_count[key] | |
month_count[key] += 1 | |
else | |
month_count[key] = 1 | |
end | |
time_counter += 2.weeks | |
end | |
month_count.map{|year_month, count| year_month if count > 2}.compact | |
end | |
puts "#{paycheck_count(Date.new(2017,9,8), 5).join(' ')} have extra paychecks" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment