|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
Hi,
Does anyone have the idea of how 'sort' function is implemented in the class 'Array'? Thanks!!! |
|
#2
|
|||
|
|||
|
I know Ruby code isn't exactly fully documented, but its always worth a look.. Here is what the Array#sort docs say:
Returns a new array created by sorting self. Comparisons for the sort will be done using the <=> operator or using an optional code block. The block implements a comparison between a and b, returning -1, 0, or +1. See also Enumerable#sort_by. a = [ "d", "a", "e", "c", "b" ] a.sort #=> ["a", "b", "c", "d", "e"] a.sort {|x,y| y <=> x } #=> ["e", "d", "c", "b", "a"] Unless there was more to your question, as the docs say, sort uses the <=> operator or a block. Not sure if this answers your question or not. If not you may have to elaborate |
|
#3
|
|||
|
|||
|
Quote:
Thank you !!! |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Ruby Programming > Sorting |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|