Melanie Fielder
10/22/2003 4:05:00 PM
"Warren Brown" <wkb@airmail.net> skrev i en meddelelse
news:000201c39824$58f435b0$4d4da8c0@home...
[snip]
> This came up in a routine where I was trying to find the "best"
> element in a list. There were three qualities that I was using to
> determine "bestness": quality1, quality2, and quality3. Eventually I
> got down to the line where I need to decide if the current word is
> "better" than my current "best". The condition started to look like:
[snip]
> 4) Is there some other concise way to achieve what I am trying to
> do?
Why not use Array#sort to identify the best element ?
Like this. A subarray consists of the 3 qualities.
irb(main):001:0> q = [[3, 2, 1], [3, 1, 2], [2, 3, 1], [2, 1, 3]]
=> [[3, 2, 1], [3, 1, 2], [2, 3, 1], [2, 1, 3]]
irb(main):002:0> q.sort
=> [[2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
irb(main):003:0>
--
Simon Strandgaard