![](/img/trans.png)
[英]Iterating over an array and searching the matching element with a given string in ruby
[英]ruby array with arrays how to get the array number when iterating over each of them and searching by number
如果我从 params 得到类似 165 的值。这是数组中第 3 个数组中包含的数字,共 9 个。如何获得数组的这个数字?
range = 50..450
cutter = range.last/50
b = range.each_slice(range.last/cutter).to_a
b #=> [[50, 51,..., 99],..., [400, 401,..., 450]]
如何获得?
您想要的数组方法是find_index
。 我认为这会做你想做的:
b.find_index {|a| a.include?(165)}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.