Decorate-sort-undecorate idiom: Difference between revisions

Line 645:
<pre>a is site Code Rosetta programming chrestomathy
chrestomathy programming Rosetta Code site is a</pre>
 
{{incorrect|Lua|recalculates length on every comparison}}
However, for this same reason, there is no point doing the decorate, sort, undecorate in practice. You can simply do this:
<syntaxhighlight lang="lua">function lengthOrder (a, b)
return #a < #b
end
 
local list = {"Rosetta", "Code", "is", "a", "programming", "chrestomathy", "site"}
table.sort(list, lengthOrder)
print(unpack(list))</syntaxhighlight>
{{out}}
<pre>a is site Code Rosetta programming chrestomathy</pre>
 
=={{header|Nim}}==
31

edits