Difference between revisions of "Sort in reverse order"

From CodeCodex

(Ruby)
(Erlang)
Line 1: Line 1:
 
==Implementations==  
 
==Implementations==  
 +
===Erlang===
 +
<pre>
 +
reverse_sort(List) ->
 +
    lists:reverse( lists:sort(List) ).
 +
</pre>
 +
 
===Java===
 
===Java===
  
<highlightsyntax language="java122">
+
<pre class="java">
 
Arrays.sort (myArray, Collections.reverseOrder());
 
Arrays.sort (myArray, Collections.reverseOrder());
</highlightsyntax>
+
</pre>
  
 
===Ruby===
 
===Ruby===
<pre>
+
<pre class="ruby">
myArray.sort.reverse
+
def reverse_sort(ary)
 +
  ary.sort.reverse
 +
end
 
</pre>
 
</pre>
  
 +
[[Category:Erlang]]
 
[[Category:Java]]
 
[[Category:Java]]
 
[[Category:Ruby]]
 
[[Category:Ruby]]
 
[[Category:Arrays]]
 
[[Category:Arrays]]

Revision as of 03:25, 2 March 2011

Implementations

Erlang

reverse_sort(List) ->
    lists:reverse( lists:sort(List) ).

Java

Arrays.sort (myArray, Collections.reverseOrder());

Ruby

def reverse_sort(ary)
  ary.sort.reverse
end