我有一个包含 12 个元素的数组total
,每个元素代表和 int。例如total[0] = 1
. 我有另一个remaining
数组total
- occupied spaces
。 remaining
将具有更少的元素total
。
我想编写一个方法来查找数组中连续整数之间total
存在 >=size
间隙的实例。例如:
If `foo.total = [1,2,6,7,8,9,]`
then when I call `foo.number_of_slots_available(3)`
I get `2` (because 3,4,5 is not included and 10,11,12 is not included)
以下是我的方法的开始:
def number_of_slots(size)
total_array = (1..12).to_a
occupied_spaces = some_map.to_a
remaining_array = total_array - occupied_spaces
return ????
end