Jump to content

Sort using a custom comparator: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 904:
add
Cat</pre>
 
=={{header|Elena}}==
ELENA 5.0 :
Line 1,155 ⟶ 1,156:
end do
end program CustomComparator</lang>
 
=={{header|FreeBASIC}}==
<lang freebasic>' version 23-10-2016
Line 2,356 ⟶ 2,358:
map { [ $_, length, lc ] }
@strings;</lang>
 
=={{header|Perl 6}}==
<lang perl6>my @strings = <Here are some sample strings to be sorted>;
my @sorted_strings = sort { $^a.chars <=> $^b.chars or $^a.lc cmp $^b.lc }, @strings;
.say for @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:
 
say @sorted_strings = sort -> $x { [ $x.chars, $x.lc ] }, @strings;</lang>
 
=={{header|Phix}}==
Line 2,614 ⟶ 2,607:
;; -> '("words" "pile" "Some" "of")
</lang>
 
=={{header|Perl 6Raku}}==
(formerly Perl 6)
<lang perl6>my @strings = <Here are some sample strings to be sorted>;
my @sorted_strings = sort { $^a.chars <=> $^b.chars or $^a.lc cmp $^b.lc }, @strings;
.say for @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:
 
say @sorted_strings = sort -> $x { [ $x.chars, $x.lc ] }, @strings;</lang>
 
=={{header|REXX}}==
10,333

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.