Last Friday of each month: Difference between revisions

Content added Content deleted
(→‎{{header|Groovy}}: new solution)
Line 538: Line 538:
=={{header|J}}==
=={{header|J}}==


<lang j>require'dates'
<lang j>require 'dates'
last_fridays=: 12 {. [:({:/.~ }:"1)@(#~ 5 = weekday)@todate (i.366) + todayno@,&1 1</lang>
last_fridays=: 12 {. [: ({:/.~ }:"1)@(#~ 5 = weekday)@todate (i.366) + todayno@,&1 1</lang>


In other words, start from January 1 of the given year, and count forward for 366 days, keeping the fridays. Then pick the last remaining day within each represented month (which will be a friday because we only kept the fridays). Then pick the first 12 (since on a non-leap year which ends on a thursday we would get an extra friday).
In other words, start from January 1 of the given year, and count forward for 366 days, keeping the Fridays. Then pick the last remaining day within each represented month (which will be a Friday because we only kept the Fridays). Then pick the first 12 (since on a non-leap year which ends on a Thursday we would get an extra Friday).


Example use:
Example use: