ruby - Use hash select for an array -



ruby - Use hash select for an array -

i have hash

h = {a=> 1, b=> 2, c=> 3}

and array

a = [a, b]

is possible utilize

h.select {|k,v| k == array_here?}

to select elements array exists in hash?

i found solution

h.select {|k,v| a.include?(k) }

you're going backwards. seek this:

a.select {|e| h.has_key? e }

ruby

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -