Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的代码是
a={"1"=>"adi","2"=>"amar","3"=>"rave","4"=>"sum"} arr=["1","5","3"]
如果哈希中存在数组值,我想提取所有这样的值
result =["adi","rave"]
不使用任何循环。有可能吗
你可以这样做:
a.values_at(*arr).compact # => ["adi", "rave"]