ruby - All keys from hash with matching array values in Rails 4 -


i have hash such as:

char_map = {   :x => %w[something]   :y => %w[something2 something]   :z => %w[something3 something1]   :r => %w[something something3]   ...   ... } 

and have array

x = ['something', 'something3'] 

now hash char_map want list of keys values in it's corresponding value array part of array x

so array x should keys x , r output

@recommendation_factors.each |rf|   @rec_list = char_map.detect{|h| h == rf.recommendation_factor} end 

i tried above keeps on returning empty array. :/

try one

char_map.keys.select { |k| (char_map[k] - x).empty? } 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -