Last Friday of each month: Difference between revisions

CoffeeScript
(CoffeeScript)
Line 123:
2012-Dec-28
</pre>
=={{header|CoffeeScript}}==
<lang coffeescript>
last_friday_of_month = (year, month) ->
# month is 1-based, JS API is 0-based, then we use
# non-positive indexes to work backward relative to the
# first day of the next month
i = 0
while true
last_day = new Date(year, month, i)
if last_day.getDay() == 5
return last_day.toDateString()
i -= 1
days_in_month = (year, month) ->
# This is a dirty trick; there may be a nicer API.
new Date(year, month+1, 0).getDate()
 
print_last_fridays_of_month = (year) ->
for month in [1..12]
console.log last_friday_of_month year, month
do ->
year = parseInt process.argv[2]
print_last_fridays_of_month year
</lang>
output
<lang>
> coffee last_friday.coffee 2012
Fri Jan 27 2012
Fri Feb 24 2012
Fri Mar 30 2012
Fri Apr 27 2012
Fri May 25 2012
Fri Jun 29 2012
Fri Jul 27 2012
Fri Aug 31 2012
Fri Sep 28 2012
Fri Oct 26 2012
Fri Nov 30 2012
Fri Dec 28 2012
</lang>
 
 
=={{header|Go}}==
<lang go>package main
Anonymous user