Jump to content

Find the last Sunday of each month: Difference between revisions

Line 2,703:
2013-11-24
2013-12-29
</pre>
 
 
=={{header|Smalltalk}}==
<lang Smalltalk>
Pharo Smalltalk
 
[ :yr | | firstDay firstSunday |
firstDay := Date year: yr month: 1 day: 1.
firstSunday := firstDay addDays: (1 - firstDay dayOfWeek).
(0 to: 52)
collect: [ :each | firstSunday addDays: (each * 7) ]
thenSelect: [ :each |
(((Date daysInMonth: each monthIndex forYear: yr) - each dayOfMonth) <= 6) and: [ each year = yr ] ] ]
</lang>
{{out}}
<pre>
Send value: 2013 to the above blok to return an array:
(29 January 2012 26 February 2012 25 March 2012 29 April 2012 27 May 2012 24 June 2012 29 July 2012 26 August 2012 30 September 2012 28 October 2012 25 November 2012 30 December 2012)
</pre>
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.