Decorate-sort-undecorate idiom: Difference between revisions

Content added Content deleted
(Added Lua version)
Line 596: Line 596:


=={{header|Lua}}==
=={{header|Lua}}==
Nice and straighforward because Lua has 'first-class' functions and its 'table.sort' accepts a custom compare function as a second argument.
Lua's 'table.sort' accepts a custom compare function as a second argument.
<syntaxhighlight lang="lua">-- Decorate, sort, undecorate function
<syntaxhighlight lang="lua">-- Decorate, sort, undecorate function
function dsu (tab, keyFunc)
function dsu (tab, keyFunc)