simpleton
unread,Mar 8, 2012, 3:50:30 PM3/8/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to rubyonra...@googlegroups.com
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?