Jayaram
Jayaram

Reputation: 839

filter Hashes in Ruby

q = {"It", "was", "the", "best", "of", "times", "it", "was", "the", "worst", "of", "times"}

write an expression to return

wasworsttimes

without using any character or string literals.

Can someone help me figure out how to do this?

Upvotes: 0

Views: 105

Answers (1)

sepp2k
sepp2k

Reputation: 370435

I'm pretty sure the hash should be {"it", "was",...} (lower case i at the beginning).

Then this literal will create the following hash {"it"=>"was", "the"=>"worst", "of"=>"times"}.

Note that the words you're supposed to extract are the value of the hash. So you can just use Hash's values method to get them and Array's join method to turn the array of values into a string.

Upvotes: 1

Related Questions