我有一个数组:
array = ["One is enough", "Two is a couple", "Where's the beef?", "One"]
然后我有一个哈希:
hash = {"one" => "Defined",
"two" => "Test"
}
我需要遍历每个对象array
并查看该对象是否包含在hash
键中找到的子字符串。如果找到,它应该返回该hash
值。否则,它应该返回undefined
。最终目标是创建一个如下所示的数组:
final_array = ["Defined,"Test","Undefined","Defined"]
如何有效地编写该循环?