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

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -