Created
September 14, 2009 18:58
-
-
Save javan/186847 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Takes a collection of Stocks and moves the closed ones to the end | |
def closed_stocks_last(stocks) | |
open, closed = [], [] | |
stocks.each do |stock| | |
if stock.closed? | |
closed << stock | |
else | |
open << stock | |
end | |
end | |
open + closed | |
end | |
# I've found that doing: | |
stocks.sort_by { |s| s.closed? ? 1 : 0 } | |
# Does not preserve the original ordering, but using the method above does. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment