我有
a = ["a","d","c","b","c"]
并需要打印类似的东西(按出现次数排序)
c:3
b:2
我明白第一部分(发现非唯一)是:
b = a.select{ |e| a.count(e) > 1 }
=> ["c","c"]
要么
puts b.select{|e,c| [e,a.count(e)] }.uniq
c
b
如何输出每一个非唯一的数量排序次数?
puts a.uniq.
map { | e | [a.count(e),e] }.
select { | c,_ | c > 1 }.
sort.reverse.
map { | c,e | "#{e}:#{c}" }