給定一個符號數組,如何迭代數組,並存儲匹配對的數組索引?搜索數組符號 - Ruby
foo = [:date, :recorded_at, :scheduled_for, :amount, :activity, :pending ]
例如,如果你搜索「recorded_at」和「活動」,它應該返回[1,4]
我覺得像這樣的工作:
bar = ['recorded_at','activity']
buzz = bar.each{|i| foo.index(i.to_sym)}
然而,這只是返回字符串,["foo", "bar"]
,而不是實際的數組索引。
這裏的常客,發現牛人一枚,哈哈! – scottxu 2014-11-04 03:36:17
ni zen me ke yi yong zhong wen ne – dddd1919 2014-11-04 03:42:50
好的,我下載yong pinyin! – scottxu 2014-11-04 03:44:54