Day of the week: Difference between revisions
Content added Content deleted
(→{{header|JavaScript}}: ES6) |
|||
Line 207:
more functional style of composition:
<lang applescript>
filter(xmasIsSunday, range(2008, 2121))▼
end run▼
on xmasIsSunday(y)
tell (current date)
Line 224 ⟶ 217:
-- TEST ------------------------------------------------------------------
on run
▲ filter(xmasIsSunday, range(2008, 2121))
▲end run
-- GENERIC FUNCTIONS -----------------------------------------------------
-- filter :: (a -> Bool) -> [a] -> [a]
on filter(f, xs)
set lng to length of xs▼
end script▼
repeat with i from 1 to lng
set
if lambda(v, i, xs) then set end of lst to v▼
▲ set lng to length of xs
end tell
▲ set end of lst to v
end if▼
▲ end repeat
end filter
-- Lift 2nd class handler function into 1st class script wrapper
-- mReturn :: Handler -> Script
on mReturn(f)
if class of f is script then
f
▲ else
property lambda : f
end script
end mReturn
-- range :: Int -> Int -> [Int]
on range(m, n)
set
else
set d to 1
end if
set lst to {}
repeat with i from
set end of lst to i
end repeat
return lst
Line 255 ⟶ 268:
{{Out}}
<
2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118}</
=={{header|AutoHotkey}}==
|