Jump to content

Last Friday of each month: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
m (use day_of_week())
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 177:
2012-12-28</pre>
 
=={{Headerheader|AppleScript}}==
 
{{Trans|JavaScript}}
Line 506:
2012-11-30
2012-12-28</pre>
 
 
=={{header|AutoHotkey}}==
Line 1,046 ⟶ 1,045:
2012-12-28
</pre>
 
=={{header|Elm}}==
<lang elm>import Html exposing (Html, Attribute, text, div, input)
Line 2,018:
2012-11-30
2012-12-28</pre>
 
 
=={{header|LiveCode}}==
Line 2,189 ⟶ 2,188:
2012-11-30
2012-12-28</pre>
 
 
=={{header|Mathematica}}==
Line 2,543 ⟶ 2,541:
 
ocaml unix.cma str.cma -I +calendar calendarLib.cma last_fridays.ml 2012
 
 
=={{header|Oforth}}==
Line 2,644 ⟶ 2,641:
2012-12-28
</pre>
 
=={{header|Perl 6}}==
<lang perl6>sub MAIN (Int $year = Date.today.year) {
my @fri;
for Date.new("$year-01-01") .. Date.new("$year-12-31") {
@fri[.month] = .Str if .day-of-week == 5;
}
.say for @fri[1..12];
}</lang>
 
Example:
<pre>$ ./lastfri 2038
2038-01-29
2038-02-26
2038-03-26
2038-04-30
2038-05-28
2038-06-25
2038-07-30
2038-08-27
2038-09-24
2038-10-29
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 classify *.month, Date.new("$year-01-01") .. Date.new("$year-12-31");
}</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.
 
Another variation where the data flow can be read left to right using feed operators:
 
<lang perl6>sub MAIN (Int $year = Date.today.year) {
.say for Date.new("$year-01-01") .. Date.new("$year-12-31") ==> classify *.month ==>
map *.value.reverse.first: *.day-of-week == 5
}</lang>
 
=={{header|Phix}}==
Line 3,239 ⟶ 3,196:
Fri 28 Dec 2012
</pre>
 
=={{header|Perl 6Raku}}==
(formerly Perl 6)
<lang perl6>sub MAIN (Int $year = Date.today.year) {
my @fri;
for Date.new("$year-01-01") .. Date.new("$year-12-31") {
@fri[.month] = .Str if .day-of-week == 5;
}
.say for @fri[1..12];
}</lang>
 
Example:
<pre>$ ./lastfri 2038
2038-01-29
2038-02-26
2038-03-26
2038-04-30
2038-05-28
2038-06-25
2038-07-30
2038-08-27
2038-09-24
2038-10-29
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 classify *.month, Date.new("$year-01-01") .. Date.new("$year-12-31");
}</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.
 
Another variation where the data flow can be read left to right using feed operators:
 
<lang perl6>sub MAIN (Int $year = Date.today.year) {
.say for Date.new("$year-01-01") .. Date.new("$year-12-31") ==> classify *.month ==>
map *.value.reverse.first: *.day-of-week == 5
}</lang>
 
=={{header|REBOL}}==
10,333

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.