Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
例如,我有数据:
a,b,c,a,c,d
可能还有其他数据,例如e,f,g等。
怎么做?
a = [:a,:b,:c,:a,:c,:d] p h = a.each_with_object(Hash.new(0)){|i,h| h[i] += 1} p h.keys # >> {:a=>2, :b=>1, :c=>2, :d=>1} # >> [:a, :b, :c, :d]