Sort using a custom comparator: Difference between revisions
Content added Content deleted
SqrtNegInf (talk | contribs) m (→{{header|Perl}}: sundry clean-up) |
SqrtNegInf (talk | contribs) m (→{{header|Raku}}: simplified) |
||
Line 3,132: | Line 3,132: | ||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
(formerly Perl 6) |
(formerly Perl 6)<br> |
||
Primary sort by length of string, then break ties by sorting alphabetically (ignoring case). |
|||
<lang perl6>my @strings = <Here are some sample strings to be sorted>; |
<lang perl6>my @strings = <Here are some sample strings to be sorted>; |
||
put @strings.sort:{.chars, .lc}; |
|||
⚫ | |||
.say for @sorted_strings; |
|||
{{out}} |
|||
<pre>be to are Here some sample sorted strings |
|||
# If instead the function you feed to <code>sort</code> is of arity 1, it will do the Schwartzian transform for you, automatically sorting numeric fields numerically, and strings fields stringily: |
|||
be to are Here some sample sorted strings |
|||
</pre> |
|||
⚫ | |||
=={{header|REXX}}== |
=={{header|REXX}}== |