簡體   English   中英

帶有數組的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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM