brabuhr
11/11/2008 11:05:00 PM
On Tue, Nov 11, 2008 at 5:29 PM, Stuart Clarke
<stuart.clarke1986@gmail.com> wrote:
> I have a quick brain teaser. I have an array full of data broken down
> into indivdual entries. I running a simple if statement to check for an
> entry in the array, if my if statement finds that entry its prints out
> that entry. I want to add an extra step into this so, when my if
> statement finds an entry, I want it to look at the next entry and check
> for something else, if it finds that, I want to look at the next entry
> and check for something else, if it finds all of the three entries in a
> row, it prints out "You have found what you want"
>
> Any ideas?
Not as pretty as each_cons, but:
def foo?(array, a, b, c)
i = array.index(a)
return false unless i
if (array[i+1] == b) and (array[i+2] == c)
puts "You have found what you want"
return true
end
false
end
p foo?([1,2,3,4,5,6], 3, 4, 5)
p foo?([1,2,3,4,5,6], 3, 4, 6)