Last Friday of each month: Difference between revisions

m
(→‎{{header|Groovy}}: new solution)
Line 538:
=={{header|J}}==
 
<lang j>require 'dates'
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 fridaysFridays. Then pick the last remaining day within each represented month (which will be a fridayFriday because we only kept the fridaysFridays). Then pick the first 12 (since on a non-leap year which ends on a thursdayThursday we would get an extra fridayFriday).
 
Example use:
892

edits