Sort using a custom comparator: Difference between revisions

no edit summary
No edit summary
Line 2,435:
A
</pre>
 
=={{header|Maple}}==
<lang Maple>Compare_fn:= proc(s1, s2)
local len1, len2;
len1 := StringTools:-Length(s1);
len2 := StringTools:-Length(s2);
if (len1 > len2) then
return true;
elif (len1 < len2) then
return false;
else # ascending lexicographic order for strings of equal length / case insensitive
StringTools:-CompareCI(s1, s2);
end if;
end proc:
 
L := ["Here", "are", "some", "sample", "strings", "to", "be", "sorted", "Tooo"];
sort(L, Compare_fn);</lang>
{{out}}
<pre>
["strings", "sample", "sorted", "Here", "some", "Tooo", "are", "be", "to"]
</pre>
 
 
=={{header|Mathematica}}==
Anonymous user