Adam Akhtar wrote:
> the reg exp. looks good

You should never consider a regex good looking.  regexes should be 
avoided whenever possible in favor of String methods.  Better solutions 
have been posted.


Robert Klemme wrote:
> I would use another algorithm because of efficiency:
>
> list.delete_if 

Repeatedly deleting elements from the middle of an array is certainly 
not efficient.  Also, suppose the results are:

[Adam Bobby wILd]

Looking at the results, you would have no way of knowing whether there 
were duplicates spelled: adam, bobby, and wild.  Therefore, the case of 
the results appears to be irrelevant.  If the case of the results is 
irrelevant, then just providing the set is enough:


require 'set'

# ensure random order
list = %w{adam Adam bobby Bobby wild wILd}.sort_by { rand }

results = Set.new
list.each do |elmt|
  results << elmt.downcase
end

p results

--output:--
#<Set: {"bobby", "wild", "adam"}>


-- 
Posted via http://www.ruby-forum.com/.