I have an array called *headlines* with lots of strings in it. Each string
has a #rhyme_keys methods available on it which essentially gives it one of
let's say 100 types.
I want to remove all strings from the array who's #rhyme_key type is unique
to the array (i.e. if 2 or more strings both have the same of any of the
100 types, they can stay).

I've tried starting off here:

#store all possible types in a new array
rhyme_keys_array = [] << headlines.map{|i| i.rhyme_keys }

#convert it to a hash so that the 100 types are mapped as keys, and their
frequency is mapped as values
rhyme_keys_array.flatten.inject(Hash.new(0)){|i,c| i[c]+=1; i}

#Now I don't know how to check against this new hash. Theoretically I think
it's like the idea below, but I don't know how to express it syntactically:

hrk = headlines.map{|i| i.rhyme_keys }
if hrk.count < 2 (in the value of the corresponding rhyme_key in the hash)
then remove i from headlines.

Does this make sense?

You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/3KQz1BdhnXsJ.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
postedMar 8, '12 at 8:50p
activeMar 8, '12 at 8:50p

1 user in discussion

Simpleton: 1 post



site design / logo © 2021 Grokbase