[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Unique values in hash?

Dan Diebolt

12/16/2008 10:10:00 AM

[Note: parts of this message were removed to make it a legal post.]

h=Hash[*%w(a alex b mary c alex).flatten]
=> {"a"=>"alex", "b"=>"mary", "c"=>"alex"}

irb(main):014:0> h.values
=> ["alex", "mary", "alex"]

irb(main):015:0> h.values.uniq
=> ["alex", "mary"]

--- On Tue, 12/16/08, Vapor .. <vaqas.ashraf@gmail.com> wrote:
From: Vapor .. <vaqas.ashraf@gmail.com>
Subject: Unique values in hash?
To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
Date: Tuesday, December 16, 2008, 3:48 AM

Hi,

I have a hash that contains duplicate data, for example, :username =>
"alex" comes many times.
I want to loop around and print their names just once (only unique). In
simple loop it would print "alex" repeatedly.

Thanks.
--
Posted via http://www.ruby-....