Jump to content

Palindrome dates: Difference between revisions

→‎{{header|AppleScript}}: Added subheadings
m (added a clause.)
(→‎{{header|AppleScript}}: Added subheadings)
Line 44:
 
=={{header|AppleScript}}==
===Procedural===
 
<lang applescript>on palindromeDates(startYear, targetNumber)
script o
Line 81:
<pre>{"2021-12-02", "2030-03-02", "2040-04-02", "2050-05-02", "2060-06-02", "2070-07-02", "2080-08-02", "2090-09-02", "2101-10-12", "2110-01-12", "2111-11-12", "2120-02-12", "2121-12-12", "2130-03-12", "2140-04-12"}</pre>
 
===Functional===
 
Or, for a functional composition (rather than a procedure), we can return a count and two samples of all palindromic dates for years in the range [2021 .. 9999], by assembling a function from reusable generics:
 
<lang applescript>use AppleScript version "2.4"
Line 91 ⟶ 90:
-- palinYearsInRange :: Int -> Int -> [String]
on palinYearsInRange(fromYear, toYear)
 
concatMap(palinDay(iso8601Formatter()), ¬
enumFromTo(fromYear, toYear))
end palinYearsInRange
 
Line 109 ⟶ 108:
set {m, m1, d, d1} to reverse of characters of s
set mbDate to s & "-" & m & m1 & "-" & d & d1
 
if missing value is not ¬
(fmtr's dateFromString:(mbDate & ¬
Line 124:
 
 
--------------------------- TEST- ---------------------------
on run
set xs to palinYearsInRange(2021, 9999)
Line 137:
 
 
--------------------- GENERIC FUNCTIONS ---------------------
 
 
-- concatMap :: (a -> [b]) -> [a] -> [b]
Line 178 ⟶ 177:
end if
end mReturn
 
 
-- iso8601Formatter :: () -> NSISO8601DateFormatter
Line 188:
end tell
end iso8601Formatter
 
 
-- unlines :: [String] -> String
9,659

edits

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