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
Post a Comment