Using Ruby 2.4, I have an array of unique, ordered numbers, for example
[1, 7, 8, 12, 14, 15]
How do I find the first two elements whose differ
You could use each_cons and find to get the first element from the array of pairs where the second element less the first one is equal to 1:
each_cons
find
p [1, 7, 8, 12, 14, 15].each_cons(2).find { |a, b| b - a == 1 } # => [7, 8]