Understanding ruby array sort

Posted by user257797 on Stack Overflow See other posts from Stack Overflow or by user257797
Published on 2010-04-14T12:47:57Z Indexed on 2010/04/14 13:23 UTC
Read the original article Hit count: 309

Filed under:
|
|

I am having a problem understanding how array.sort{|x,y| block} works exactly,hence how to use it?

ruby-doc example:

   a = [ "d", "a", "e", "c", "b" ]
   a.sort                    #=> ["a", "b", "c", "d", "e"]
   a.sort {|x,y| y <=> x }   #=> ["e", "d", "c", "b", "a"]

thanks

© Stack Overflow or respective owner

Related posts about ruby

Related posts about arrays