P
Pete Hodgson
Hi Folks,
Given a sorted enumeration I need to find the first gap in a sequence.
e.g.
3 == find_gap [1,2,4,5]
nil == find_gap [1,2,3,4]
Here's the best I can come up with
def first_gap( seq )
seq.each_cons(2) do |l,r|
_next = l.next
return _next if r!= _next
end
nil
end
but it seems rather ugly. Anyone have a more elegant implementation?
Cheers,
Pete
Given a sorted enumeration I need to find the first gap in a sequence.
e.g.
3 == find_gap [1,2,4,5]
nil == find_gap [1,2,3,4]
Here's the best I can come up with
def first_gap( seq )
seq.each_cons(2) do |l,r|
_next = l.next
return _next if r!= _next
end
nil
end
but it seems rather ugly. Anyone have a more elegant implementation?
Cheers,
Pete