Order two numerical lists: Difference between revisions
Content deleted Content added
Line 56:
TRUE
</pre>
=={{header|AppleScript}}==
{{Trans|JavaScript}}
<= is not defined over lists in AppleScript
<lang AppleScript>-- <= for lists
-- compare :: [a] -> [a] -> Bool
on compare(xs, ys)
if length of xs = 0 then
true
else
if length of ys = 0 then
false
else
set {hx, txs} to uncons(xs)
set {hy, tys} to uncons(ys)
if hx < hy then
true
else if hx > hy then
false
else
compare(txs, tys)
end if
end if
end if
end compare
-- TEST
on run
{compare([1, 2, 1, 3, 2], [1, 2, 0, 4, 4, 0, 0, 0]), ¬
compare([1, 2, 0, 4, 4, 0, 0, 0], [1, 2, 1, 3, 2])}
end run
---------------------------------------------------------------------------
-- GENERIC FUNCTION
-- uncons :: [a] -> Maybe (a, [a])
on uncons(xs)
if length of xs > 0 then
{item 1 of xs, rest of xs}
else
missing value
end if
end uncons</lang>
{{Out}}
<lang AppleScript>{false, true}</lang>
=={{header|AutoHotkey}}==
|