Decorate-sort-undecorate idiom: Difference between revisions

Content added Content deleted
m (→‎{{header|JavaScript}}: Added a variant)
m (→‎{{header|Phix}}: added "reverse()" output, to match JavaScript)
Line 513: Line 513:
<span style="color: #0000FF;">?</span><span style="color: #000000;">decorate_sort_undecorate</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">split</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"Rosetta Code is a programming chrestomathy site"</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">)</span>
<span style="color: #0000FF;">?</span><span style="color: #000000;">decorate_sort_undecorate</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">split</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"Rosetta Code is a programming chrestomathy site"</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">)</span>
<!--</syntaxhighlight>-->
<!--</syntaxhighlight>-->
Same output. The commented out line shows use of std sort by putting lengths before words and returning vslice(s,2), and making it all a one-liner.
Same output. The commented out line shows use of std sort by putting lengths before words and returning vslice(s,2), and making it all a one-liner.<br>
Like the JavaScript entry but w/o any faff, both methods could also accept (say) reverse as the function, which would yield the following output:
<pre>
{"a","Rosetta","Code","site","programming","is","chrestomathy"}
</pre>


=={{header|Python}}==
=={{header|Python}}==