How to filter this array?

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?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs