【发布时间】:2020-12-07 13:00:06
【问题描述】:
我有两个数组
array_input = %w[one two three two]
array_compare = %w[one two three four five]
如果值存在于输入数组中,我想从 array_compare 数组中提取“最高”索引。所需的输出是2,因为three 存在于输入数组和compare 数组中。
我试过了
val = nil
array_compare.reverse_each do |v|
val = v and break if array_input.include? v
end
但它没有设置 val。
【问题讨论】: