简体   繁体   中英

ruby array with arrays how to get the array number when iterating over each of them and searching by number

if I get from params something like a 165. and this is number contains in array number 3 of 9. how to get this number of the array?

range = 50..450
cutter = range.last/50
b = range.each_slice(range.last/cutter).to_a

b #=> [[50, 51,..., 99],..., [400, 401,..., 450]]

How to get it?

The array method you want is find_index . I think this will do what you want:

b.find_index {|a| a.include?(165)}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM