Last Friday of each month: Difference between revisions

→‎{{header|Perl 6}}: added alternative solution
m (→‎{{header|Perl 6}}: remove final $_)
(→‎{{header|Perl 6}}: added alternative solution)
Line 502:
2038-11-26
2038-12-31</pre>
 
A solution without a result array to store things in:
 
<lang perl6>sub MAIN (Int $year = Date.today.year) {
say ~.value.reverse.first: *.day-of-week == 5
for (Date.new("$year-01-01") .. Date.new("$year-12-31")).classify: *.month;
}</lang>
 
Here, <code>.classify</code> sorts the dates into one bin per month (but preserves the order in each bin). We then take the list inside each bin (<code>.value</code>) and find the last (<code>.reverse.first</code>) date which is a Friday.
 
=={{header|PHP}}==
Anonymous user