views:

20

answers:

1

I have an array of structs. Each struct has the following two attributes:

  • win %
  • # of wins

I want to sort the array of structs by win %; however, for only those structs with at least 3 wins.

Any suggestions?

+1  A: 

First use select to take only the objects with at least 3 wins, then use sort_by to sort by the percentage:

array.select {|x| x.num_of_wins >= 3}.sort_by {|x| x.win_percent}
sepp2k