From: Robert Klemme Date: 2007-06-28T20:50:02+09:00 Subject: Re: Can i calculate the data number in array? On 28.06.2007 12:56, Robert Dober wrote: > On 6/28/07, Robert Klemme wrote: > >> Btw, thanks for leaving the inject solution to me. :-) > Shame on you!!! ;) Um, why? Somehow I don't get the joke, sorry. :-) > But that is not what OP asked for > > (a|[]).map{|e|a.grep(e).size} ### I know it might not work as we use > #=== here Sorry, Robert, but I don't think this is what the OP was asking for: irb(main):001:0> a = %w{a a a b b c c c d d e} => ["a", "a", "a", "b", "b", "c", "c", "c", "d", "d", "e"] irb(main):002:0> a.map{|e|a.grep(e).size} => [3, 3, 3, 2, 2, 3, 3, 3, 2, 2, 1] Your solution repeats counts for the same string but as far as I can see from his original posting he wants counts for each string just once. > More generally we have therefore > > (a|[]).map{|e|a.select{|x|x==e}.size} > > Maybe OP preferred > ..).sort.map{... > > and sorry OP, I just needed this working break. :-) Kind regards robert