yermej
11/26/2007 5:39:00 PM
On Nov 26, 11:20 am, Lionel Bouton <lionel-subscript...@bouton.name>
wrote:
> yermej wrote the following on 26.11.2007 18:15 :
>
>
>
> > On Nov 26, 9:15 am, Sam Larbi <sla...@gmail.com> wrote:
>
> >> Note: parts of this message were removed by the gateway to make it a legal Usenet post.
>
> >> I've got an array of strings, say like:
>
> >> ["Bob", "John", "Bobby", "John"]
>
> >> I want to remove duplicates and elements that are substrings of other
> >> elements. Therefore, the above array would become:
>
> >> ["John","Bobby"]
> > This should work:
>
> > arr = ["Bob", "John", "Bobby", "John"]
> > arr.uniq!
> > arr.reject {|a| arr.any? {|b| b != a and b =~ /#{a}/}}
>
> You'll have surprises if there's a "." element...
>
> arr = ["Bob", "John", "Bobby", "John"]
> arr.uniq!
> arr.reject {|a| arr.any? {|b| b != a and a.index(b) } }
>
> seems safer and quicker to me.
>
> Lionel
Good point. Thank you.
Jeremy